Essentials
API Essentials
Content types

Content types

Infobip API supports several content types (opens in a new tab). Most API requests and responses will be either application/json or application/xml. Take a minute to find out more about the JSON format (opens in a new tab) and XML format (opens in a new tab).

Note that some API endpoints, like email sending, use multipart/form-data, so it is advisable to check the dedicated documentation page of your targeted endpoint for details.

Specify response Content-Type

You can specify the desired API response content type in one of two ways.

Accept header

The first one is by using the standard Accept (opens in a new tab) HTTP header.

Request example:

json
 
    GET /sms/1/reports HTTP/1.1
    Host: api.infobip.com
    Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
    Accept: application/json
 

Response example:

json
 
    {
        "results": []
    }
 

Path extension

If, for any reason, you are unable to modify the Accept header of your API call, there is another way to request a specific content type. To do so, append the request path with the extension corresponding to the content type of your choosing.

Content typePath extension
application/json.json
application/xml.xml

The following request:

json
 
    GET /sms/1/reports.xml HTTP/1.1
    Host: api.infobip.com
    Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
 

will result in a response with the XML format that could look something like this:

json
 

Specify request Content-Type

The content type of your request body data should be specified in the Content-Type header of the request. If not otherwise specified, API endpoints will accept either application/json or application/xml types of content.

NOTE

It is mandatory to specify the Content-Type header for API requests that contain HTTP message body data. Those are typically requests using the POST and PUT HTTP methods.

For example, you can format an SMS message in either JSON or XML, but you have to fill out the Content-Type header accordingly:

REQUEST SAMPLES
 
    POST /sms/1/text/single HTTP/1.1
    Host: api.infobip.com
    Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
    Content-Type: application/json
    
    {
       "to":"41793026727",
       "text":"Test SMS."
    }
 

Lastly, note that the API response will match the submitted content by default. However, you can modify this behavior by explicitly setting the Accept header if you wish to receive the API response in the content type different from the one used to submit request body data. This is useful when sending an e-mail in multipart/form-data format so another content type for the response is desirable:

json
 
    POST /email/1/send HTTP/1.1
    Host: api.infobip.com
    Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
    Accept: application/json
    Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
    
    ------WebKitFormBoundary7MA4YWxkTrZu0gW
    Content-Disposition: form-data; name="from"
    
    Jane Doe 
    ------WebKitFormBoundary7MA4YWxkTrZu0gW
    Content-Disposition: form-data; name="to"
    
    [email protected]
    ------WebKitFormBoundary7MA4YWxkTrZu0gW
    Content-Disposition: form-data; name="subject"
    
    Mail subject text
    ------WebKitFormBoundary7MA4YWxkTrZu0gW
    Content-Disposition: form-data; name="text"
    
    Mail body text
    ------WebKitFormBoundary7MA4YWxkTrZu0gW--
 

The above request will produce a response in JSON format.

Bad Request errors

API will try to distinguish between common mistakes and respond in an appropriate way. For example, if there is something wrong with the HTTP message body data, API will respond with the HTTP status 400 (Bad request) and the response body might look like this:

REQUEST SAMPLES
 
    {
        "requestError": {
            "serviceException": {
                "messageId": "BAD_REQUEST",
                "text": "Bad request"
            }
        }
    }
 

This response can have several causes, and here are some common ones:

  • The content-type header is missing
  • Content-type does not match the submitted body data
  • Submitted body data does not respect the JSON or XML format

However, unrecognized parameters in API request body data will be ignored without the request automatically failing, as long as the request is properly formatted. Because of this, it is recommended to consult dedicated documentation of the targeted API endpoint and the list of accepted parameters defined there.

Response parsing

When parsing the API responses, make sure to adhere to JSON (opens in a new tab) or the XML (opens in a new tab) specifications. There are specific details associated with each one; for example, JSON format does not guarantee the order of name/value pairs in objects. Therefore, you should never depend on the order of properties when parsing JSON API responses.

Depending on your language of choice, there is either native support for JSON / XML parsing built-in, or you might use some external library that handles it.

Need assistance

Explore Infobip Tutorials

Encountering issues

Contact our support

What's new? Check out

Release Notes

Unsure about a term? See

Glossary

Research panel

Help shape the future of our products
Service Terms & ConditionsPrivacy policyTerms of use