'Unexpected '<' error for post while using Postman and rails
My JSON response to be populated is as follows:
{
"vendor":
{
"name": "Mozelle Luettgen MD",
"email": "[email protected]",
"phone_no": "9999997660",
"addressline1": "Kulas Stravenue",
"addressline2": "64636 Lynch Springs",
"landmark": "Apt. 142",
"city": "South Hannaview",
"state": "North Dakota",
"country": "Palau",
"pincode": "53912-6122",
"latitude": 50.8247548421224,
"longitude": -81.8429583068792,
"status": true
}
}
My controller code for create vendor is
def create
@vendor = Vendor.new(vendor_params)
respond_to do |format|
if @vendor.save
format.html { redirect_to @vendor, notice: 'Vendor was
successfully created.' }
format.json { render :show, status: :created, location: @vendor,
:msg => { :status => "ok" , :result => @vendor.json, :message =>
"Succesfully Created" }
}
else
format.html { render :new }
format.json { render json: @vendor.errors, status:
:unprocessable_entity,
:msg =>
{ :status => "Error", :message => "Unprocessable Entity" }
}
end
end
end
def vendor_params
params.require(:vendor).permit(:name, :email, :phone_no,
:addressline1, :addressline2, :landmark,
:city, :state, :country, :pincode, :latitude, :longitude, :status,
{products_attributes: [:id, :product_name, :price]},
{vendor_products_attributes: [:id, :vendor_product_id, :vendor_id,
:product_id, :copies, :_destroy]})
end
While running this link http://localhost:3000/vendors/create_vendor with post, the status shows 200 ok, but when I look for the JSON response,for the created vendor, it throws Unexpected '<' error.What am I doing wrong.Can someone please elaborate
Solution 1:[1]
I had the same issue and was able to get it sorted by changing the syncing link
Solution 2:[2]
Make sure you do not have declared twice this var User=require('../Models/user'); object of model class both in route/user.js and main server/app.js file
You declared object two times of model class
Solution 3:[3]
This Setting in postman application helped me to resolve this problem
Global Proxy Configuration:ON
Proxy Type: HTTPS
Proxy Server: abc.xyz.abc.com:8080
Use System Proxy: OFF
Solution 4:[4]
The reason is that you might have opened the session by logging into another browser or some where else while trying to connect to postman. That is the reason you are getting "unexpected '>'".
To avoid that, login to postman with the login api and try to hit your service. It will work for sure.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Chamindi |
| Solution 2 | Marvin Fischer |
| Solution 3 | |
| Solution 4 | Shane G |

