Add Geo Category via REST API

I am trying to add a Geo category using the REST API and the response is coming back as NULL.

My request is https://api.backendless.com/v1/geo/categories/cat1 using the PUT method. I have logged in and have set the user token from the login in the HTTP header.

Is there something else I should be setting ?

This problem was in my code baseline. I was setting the HTTP header with Content-Type: application/json.

Adding categories works now.

Hi Roy!

Please, try with this request:

curl
-H application-id:<your app id>
-H secret-key:<rest secret key>
-H application-type:REST
-X PUT 
-v http://api.backendless.com/v1/geo/categories/foobarcategory

This request adds empty category in Geo service.
Check please if your query looks the same.
More information you can find here:
http://backendless.com/documentation/geo/rest/geo_adding_a_geo_category.htm

Regards,
Kate.

You also can use Content-Type: application/json (if you need):

curl
-H application-id:<your app id>
-H secret-key:<rest secret key>
-H Content-Type:application/json
-H application-type:REST
-X PUT
-v [url=http://api.backendless.com/v1/geo/categories/foobarcategory]http://api.backendless.com/v1/geo/categories/foobarcategory[/url] -d null

Hello Kate,

Yes I double checked the request as you pointed at and it is the same. I originally had an extra header of Content-Type: application/json that should not been part of the API call.

Thanks, Roy

A nice feature that could be added to the REST API document is that if the category already exists then the existing objectId is returned instead of en error statement stating that the category already exists.

The response returned when an category already exists like the following:

{“objectId”:“C3F9151E-5347-94EE-FF56-B1B141314300”,“name”:“foobar73”,“size”:0}

I don’t think that receiving an existing category (maybe already filled with some geopoints) is what the user expects when sending a request to create it. In other words, it’s more meaningful to notify him that the category already exists.

I agree that it should return that the object already exists. Should this issue be reopened?

What issue? Currently, if the category already exists, the user receives an error saying that the category exists. And if the category doesn’t exist, then it is created and the user receives the following json in response:

{"objectId":"C3F9151E-5347-94EE-FF56-B1B141314300","name":"foobar73","size":0}

If the category already exists and you call the REST API to create the category, you get a JSON response with the existing objectId {“objectId”:“C3F9151E-5347-94EE-FF56-B1B141314300”,“name”:“foobar73”,“size”:0}, and NOT a JSON messsage stating that the category already exists.

Oh, I’m sorry, I misunderstood the case.
Here you’re sending PUT request, which in principles of REST is regarded as “create or update”. So in case the category exists, it performs update, and there is no need to throw any error.
My words above would have sense in case of POST request, but unfortunately our API doesn’t provide POST request to create category.