Go to All Forums

Issue when trying to use API with response codes

In the API documentation, it shows that when a call is made there is always a response code that is returned either a 0 or some other non zero code. I am trying to write a script that will output data if it returns 0 or the message if not. In the API documentation, it shows that when a call is made there is always a response code that is returned either a 0 or some other non zero code. I am trying to write a python script that will output data if it returns 0 or the message if not.

My problem is that when I get a success I see the following:

{
    "code" : 0,
    "message" : "success",
    "data" : {
        "monitor_id" : "..."
    }
}

But when it fails I see the following:

{
    "error_code": 1001,
    "message": "Resource not found."
}

As per the Documentation, I read the following:

Responses will be in the JSON format.

JSON RESPONSE PARAMETERS

Node Name Description
code Site24x7 error code. Indicates zero for a success response and non-zero in case of an error.
message Status Message for the invoked API.
data Comprising the invoked API’s Data.

Is there a reason for the different naming as in code vs error_code

I'm trying to do something like:

if code == 0:
print 'data'
if code !=0:
print 'data'

Any help you can offer will be useful. Maybe I'm doing this wrong?

Like (2) Reply
Replies (1)

"error_code" attribute is more for our reference in web client error message handling. Users can identify the failures using HTTP status codes. Whenever there is any failure you will receive a non 2xx status code as response.

The initial plan was to always return 200 status code when we were successfully able to respond to an api call and to report any error only using "code" attribute inside the response json. But later to follow the REST standards we started notifying errors using HTTP status codes.

Sorry for the trouble as the API doc is not clear on this. We shall update the information.

Like (0) Reply

Was this post helpful?