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":"[email protected]","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

Android Android Commands Android Java Applications Application Libraries Application Stack / User Interface Bash / Shell Scripts Commands and Packages Compilation Content Management System - CMS Core Kernel C Programs Development & Build Development Environment Setup Errors & Failures Flutter git Go Language Programs Hardware Platforms HTML JAVA Programs Kernel & Device Drivers Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Monetization / Google AdSense NDK / Middleware / HAL OS Concepts PHP Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized User Interface Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded
Tags: ,

Leave a Reply / Ask Question