Instagram Subscribe Error “Invalid format for ’callback_url’”

 

I was looking to integrate the Instagram Real Time API from my application, however when I sent my request to Instagram to register my subscription I kept getting a response with the error below. After investigating this issue it turns out that Instagram is expecting the data for this request to be sent as form data (i.e. Content-Type = x-www-form-urlencoded).  This was not obvious as the other Instagram APIs I used just accepted the required parameters via the URI in parameters or via the route specified. 

When sending my request to https://api.instagram.com/v1/subscriptions  I sent my request as a POST in JavaScript I was getting the following payload returned with the error description from Instagram:

"{\"meta\":{\"error_type\":\"APISubscriptionError\",\"code\":400,\"error_message\":\"Invalid format for \\\"callback_url\\\". URL must start with \\\"http:\\/\\/\\\" or \\\"https:\\/\\/\\\"\"}}",

The issue was I was sending my requests using the ‘data’ member in my JSON like this:

WRONG

request({
            uri: url,
            method: "POST",
            data:  {
                        aspect: "media",
                        callback_url: [MY CALLBACK URL],
                        object: “tag”,
                        object_id: “Frendli”
                       }

        });

However because Instagram is looking for the data to be sent a form in the POST I had to amend the request to use the ‘form’ field in the request instead.  Once I did this all was well. See the corrected request below, for a more detailed description of how to automate this with node.js in Azure Mobile Services check out my article about how to create a Instagram subscription with Azure Mobile Services.

CORRECTED

request({
            uri: url,
            method: "POST",
            form:  {
                        aspect: "media",
                        callback_url: [MY CALLBACK URL],
                        object: “tag”,
                        object_id: “Frendli”
                       }

        });

For more developer goodness follow me on Twitter @livehands