How to fix errors related to REST Http POST & JSON for websites developed using openclassifieds / yclas

If you have used open-classifieds / yclas for developing your website and now trying to use there any of the POST api for creating new user or publishing new advertisement then its highly likely that you will receive any of the below errors,

Error while creating new user :

{"code":500,"error":"name must not be empty - email must not be empty - "}

Error while publishing new advertisement :

{ code: 500 error: "Category must not be empty - Title must not be empty - " }

Solution to the above problems is : There might be some missing configuration parameters remained to be set while doing POST.

If you are using ubuntu, you can test the POST API’s using below curl commands and configure your REST client using similar configurations.

For creating new user :

curl -k \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
-X POST \
-d '{"name":"User Testing5","email":"usertesting5@gmail.com","password":"1234567"}' https://www.YOUR_DOMAIN.com/api/v1/auth?apikey=YOUR_API_KEY

For uploading new advertisement :

curl -k \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
-X POST \
-d '{"id_user":"YOUR_USER_ID","id_category":"YOUR_CATEGORY_ID","title":"This is a Test Ad created by testuser5","description":"This is Test Description"}' https://www.YOUR_DOMAIN.com/api/v1/ads?user_token=YOUR_USER_TOKEN

In our case error occurted since we had missed to use “Accept: application/json” and “Content-Type:application/json” along with curl command, once we added that, the error resolved.

For actual parameters details refer to https://docs.yclas.com/api-documentation/#create-user

Tags: ,