Why is it important to log information regarding your API requests with Airship?

If you are an avid user of our server APIs to manage your push messaging, you're familiar with our HTTP server responses. Tracking this information is important to you in the event you need to contact us for any support issues.

Please Log your API requests and our responses

First, we recommend that you always log the HTTP response code that you get from each request. This will allow you to look back and find out if there was a problem with a particular request, or to trigger automatic retries.

API logging examples:

Successful API Request log example

Local Timestamp UTC: 2014-12-19 00:02:47  
Request Method: <[POST]>,   
Request URL: https://go.urbanairship.com/api/push/,   
Request Body: {"device_types": "all", "notification": {"alert": "Tag\n2014-12-18 16:02:47"}, "audience": {"or": [{"tag": ["test_tag"]}]}},   
Request Headers: {'Content-Length': '123', 'Accept-Encoding': 'gzip, deflate', 'Accept': 'application/vnd.urbanairship+json; version=3;', 'User-Agent': 'requests2311Machine', 'Connection': 'keep-alive', 'Content-Type': 'application/json', 'Authorization': 'Basic Q290eNFcXVMX2RkUGXBR'},   
Response Code: 202,  
Response Headers: {'transfer-encoding': 'chunked', 'data-attribute': 'push_ids', 'expires': 'Fri, 19 Dec 2014 00:02:47 GMT', 'server': 'Jetty(8.y.z-SNAPSHOT)', 'last-modified': 'Fri, 19 Dec 2014 00:02:47 GMT', 'connection': 'keep-alive, Transfer-Encoding', 'cache-control': 'max-age=0', 'date': 'Fri, 19 Dec 2014 00:02:47 GMT', 'content-type': 'application/vnd.urbanairship+json; version=3'},   
Response Body Text: {"ok":true,"operation_id":"5d971120-8712-11e4-b80b-90e2ba2901f0","push_ids":["130f4882-4fad-4100-bb29-2008b15e3636"],"message_ids":[],"content_urls":[]}

 

Unsuccessful API Request log example

Local Timestamp UTC: 2015-01-04 18:45:12  
Request Method: <[POST]>,   
Request URL: https://go.urbanairship.com/api/push/,   
Request Body: {"device_types": ["ios", "android"], "audience": {"alias": ["71caaf8"]}, "notification": {"alert": "Check your email."}},   
Request Headers: {'Authorization': 'Basic QXpUMkc3ljQ1NFcXVMXZXBR', 'Connection': 'keep-alive', 'User-Agent': 'requests2311Machine', 'Content-Type': 'application/json', 'Accept-Encoding': 'gzip, deflate', 'Accept': 'application/vnd.urbanairship+json; version=3;', 'Content-Length': '389'},   
Response Code: 503,  
Response Headers: {'Mime-Version': '1.0', 'Connection': 'close', 'Content-Type': 'text/html', 'Server': 'AkamaiGHost', 'Expires': 'Sun, 04 Jan 2015 18:45:12 GMT', 'Date': 'Sun, 04 Jan 2015 18:45:12 GMT', 'Content-Length': '274'},   
Response Body Text: <HTML><HEAD>  
<TITLE>Service Unavailable</TITLE>  
</HEAD><BODY>  
<H1>Service Unavailable - Zero size object</H1>  
The server is temporarily unable to service your request.  Please try again  
later.
Reference #15.9e5df6d8.1420397112.3b4627b8  
</BODY></HTML>

 

Retry on API errors

If you receive a 5xx response from our API, you should retry your request with an exponential backoff method. Errors happen on the internet from time to time, and our best practices recommend that if you first do not succeed, please try, try again. When retrying your API call, please insert a progressive delay, so your first retry may occur in 5 seconds, your second in 30, and progressive calls back off further until success. You may want to handle exceptions for persistent failures. Log files after persistent failures will be essential for us to diagnose the issue with you.

Authentication issues

If you received a 4xx response, there was some problem with your authentication or the structure of your request.

Examples of successful pushes

When we receive a successful push request, we return valuable information back to you about your request. A typical push response looks something like this:

{
    "ok" : true,
    "operation_id" : "df6a6b50-9843-0304-d5a5-743f246a4946",
    "push_ids": [
        "9d78a53b-b16a-c58f-b78d-181d5e242078",
    ]
}

 And a rich message like this:

{
    "ok" : true,
    "operation_id" : "df6a6b50-9843-0304-d5a5-743f246a4946",
    "push_ids": [
        "9d78a53b-b16a-c58f-b78d-181d5e242078",
    ]
    "message_ids":[
         "lXiQ4roCcCDkmxlwDnER4x"
    ]
}

The key pieces that you want to keep are the push_ids for a standard push request and the message_ids for a rich push request. The 202 OK response means that we were successful in receiving your request for processing. The operation_id is currently saved for future functionality. Along with these responses, you should also track the full payload including the exact date and time of the request.

Why should you keep this information? We can use the push_ids and message_ids to look up your push in our systems. Saving these items can help us address problems you might have had with your push request. It also saves us valuable time when trying to determine other causes for problems with your push. If you're having trouble with a push notification and receiving something other than an OK from us, please refer to our HTTP troubleshooting guide.

You can find the general docs about push notifications sent via our API here.

 

Related Content

Was this article helpful?
0 out of 0 found this helpful
Submit a request