CTRLK

Content types

|

View as Markdown

Most Infobip API requests and responses use application/json. Some endpoints use multipart/form-data for file uploads, and some support application/xml for specific use cases. Check the documentation for your target endpoint to confirm which content types it supports.

Request Content-Type

Any request that includes a message body, typically POST and PUT requests, must include a Content-Type header that matches the format of the data you are sending.

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

json
1curl -L -g 'https://{baseUrl}/sms/3/messages' \
2-H 'Authorization: {authorization}' \
3-H 'Content-Type: application/json' \
4-H 'Accept: application/json' \
5-d '{
6 "messages": [
7 {
8 "sender": "InfoSMS",
9 "destinations": [
10 {
11 "to": "41793026727"
12 }
13 ],
14 "content": {
15 "text": "This is a sample message"
16 }
17 }
18 ]
19}'

Set different response type

By default, the response format mirrors the request format. If you need the response in a different format, for example, when sending multipart/form-data but wanting a structured JSON response back, you can override this behaviour using the Accept header or a path extension.

The Accept header format

Set the Accept header to the format you want the response in, independently of the request format.

json
1POST /email/3/send HTTP/1.1
2Host: {base_url}
3Authorization: Basic {base64_credentials}
4Accept: application/json
5Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
6 
7------WebKitFormBoundary7MA4YWxkTrZu0gW
8Content-Disposition: form-data; name="from"
9 
10Jane Doe <[email protected]>
11------WebKitFormBoundary7MA4YWxkTrZu0gW
12Content-Disposition: form-data; name="to"
13 
15------WebKitFormBoundary7MA4YWxkTrZu0gW
16Content-Disposition: form-data; name="subject"
17 
18Your subject here
19------WebKitFormBoundary7MA4YWxkTrZu0gW
20Content-Disposition: form-data; name="text"
21 
22Your message here.
23------WebKitFormBoundary7MA4YWxkTrZu0gW--

Response Content-Type

You can specify the desired API response content type in one of two ways: the Accept header or path extension.

Accept header

Request example:

json
1GET /sms/3/reports HTTP/1.1
2Host: api.infobip.com
3Authorization: App {YOUR_API_KEY}
4Accept: application/json

Response example:

json
1{
2 "results": []
3}

For Bad Request schema, see: Schema reference and error handling.

Response parsing

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. For more details, see: Backwards compatibility.

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.

Path extension - legacy

If you are unable to modify the Accept header of your API call, 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:

shell
1curl 'https://api.infobip.com/sms/3/reports.xml' \
2-H 'Authorization: {authorization}'

Will result in a response with the XML format.

Further reading:


Next steps

Base URL
How to find and use your unique Infobip Base URL in every API request.

Schema reference and error handling
Bad Request schema and error response structure for all Infobip APIs.