{"_id":"594a7735887535001a81e275","project":"54eb50e5615ffc1900305a16","version":{"_id":"54eb63b859b1172100334fae","project":"54eb50e5615ffc1900305a16","forked_from":"54eb63a1867e1917009b711d","__v":28,"createdAt":"2015-02-23T17:30:32.501Z","releaseDate":"2015-02-23T17:30:32.501Z","categories":["54eb63b959b1172100334faf","54eb63b959b1172100334fb0","54eb63b959b1172100334fb1","54eb63b959b1172100334fb2","54ed8dd4ab373e2300f50eae","54ed99b2ab373e2300f50ede","55153a6de68daa2f00cff838","551546edbc466623002afe72","5515472ac28d6125001b8884","55154749c28d6125001b8885","555d9b4106dfec0d00d38ea7","5613e06e433e5735007c7708","5624bbb785a31117001c5403","56669e857cc81e0d00253f8e","568b8d837a42220d00498311","56a632277ef6620d00e2f18a","56d8147c3eb4dd0b00201aac","57a9ce2fac6db30e000d7efd","57a9cf4e944ea60e00dc3f74","58172386715dce0f00da4aa0","582dc59ee1b8692300c0dd03","589b19b4fec2730f0082e040","58b04a023529383900a759b5","58b92d1598157a0f004869bf","592e7685c58275000f20174f","59392839e376d4002f8a0474","59393064e376d4002f8a05a1","5947ae0d4005e2000f3a4fec","594a74df1d1de5001ab3517a","5954bc387a147f001b918915","59b8eeeb707542001076d3b6"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1"},"category":{"_id":"594a74df1d1de5001ab3517a","project":"54eb50e5615ffc1900305a16","version":"54eb63b859b1172100334fae","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-06-21T13:30:07.315Z","from_sync":false,"order":0,"slug":"new-getting-started","title":"Getting started"},"user":"54eb4fdedf7add210007b29b","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-06-21T13:40:05.940Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"Infobip API supports several [content types](https://en.wikipedia.org/wiki/Media_type). Most of the API requests and responses will be either of `application/json` or `application/xml` type. You can find out more about the `json` format [here](http://www.json.org/), and `xml` [here](https://www.w3.org/TR/REC-xml/). Note that some API endpoints, like e-mail sending, use `multipart/form-data` so it is advisable to check the dedicated documentation page of your targeted endpoint for details.\n\n## Specifying response content type\n\nYou can specify the desired API response content type in one of two ways.\n\n### Accept header\n\nFirst is through the usage of the standard [Accept](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept) HTTP header. For example a request:\n\n```\nGET /sms/1/reports HTTP/1.1\nHost: api.infobip.com\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\nAccept: application/json\n```\n\nwill produce a `json` formatted response that might look like this:\n\n```json\n{\n    \"results\": []\n}\n```\n\n### Path extension\n\nIf, for any reason you are unable to modify the Accept header of your API call then there is a second way of requesting a specific content type. To do that append the request path with the extension corresponding to the content type of your choosing.\n\n| content type | path extension |\n| --- | --- |\n| `application/json` | `.json` |\n| `application/xml` | `.xml` |\n\nFor example, the request:\n\n```\nGET /sms/1/reports.xml HTTP/1.1\nHost: api.infobip.com\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n```\n\nwill result in response with the `xml` format that could look something like this:\n\n```xml\n<?xml version='1.0' encoding='UTF-8'?>\n<reportResponse>\n    <results/>\n</reportResponse>\n```\n\n## Specifying request content type\n\nContent type of your request body data should be specified in the [Content-Type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type) header of the request. If not otherwise specified API endpoints will accept either `application/json` or `application/xml` types of content. \n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Notice\",\n  \"body\": \"It is mandatory to specify the Content-Type header for API requests that contain HTTP message body data. Typically those are requests using the POST and PUT HTTP methods.\"\n}\n[/block]\nFor example, you can format the sms message in either `json` or `xml`, but are required to fill out the Content-Type header accordingly:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"POST /sms/1/text/single HTTP/1.1\\nHost: api.infobip.com\\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\\nContent-Type: application/json\\n\\n{\\n   \\\"to\\\":\\\"41793026727\\\",\\n   \\\"text\\\":\\\"Test SMS.\\\"\\n}\",\n      \"language\": \"json\"\n    },\n    {\n      \"code\": \"POST /sms/1/text/single HTTP/1.1\\nHost: api.infobip.com\\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\\nContent-Type: application/xml\\n\\n<request>\\n   <to>41793026727</to>\\n   <text>Test SMS.</text>\\n</request>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\nLastly, 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 which,  in a `multipart/form-data` format so another content type for the response is desirable:\n\n```http\nPOST /email/1/send HTTP/1.1\nHost: api.infobip.com\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\nAccept: application/json\nContent-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW\n\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"from\"\n\nJane Doe <jane.doe:::at:::somecompany.com>\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"to\"\n\njohn.smith@somedomain.com\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"subject\"\n\nMail subject text\n------WebKitFormBoundary7MA4YWxkTrZu0gW\nContent-Disposition: form-data; name=\"text\"\n\nMail body text\n------WebKitFormBoundary7MA4YWxkTrZu0gW--\n```\n\nThe above request will produce a response in a `json` format.\n\n## Bad request errors requests\n\nAPI 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:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n    \\\"requestError\\\": {\\n        \\\"serviceException\\\": {\\n            \\\"messageId\\\": \\\"BAD_REQUEST\\\",\\n            \\\"text\\\": \\\"Bad request\\\"\\n        }\\n    }\\n}\",\n      \"language\": \"json\"\n    },\n    {\n      \"code\": \"<?xml version='1.0' encoding='UTF-8'?>\\n<ApiException>\\n    <requestError>\\n        <serviceException>\\n            <messageId>BAD_REQUEST</messageId>\\n            <text>Bad request</text>\\n        </serviceException>\\n    </requestError>\\n</ApiException>\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\nThis response can have several causes, here are a few of the common ones:\n* Content-Type header is missing\n* Content-Type does not match the submitted body data\n* Submitted body data does not respect the `json` or `xml` format\n\nHowever, 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 with the dedicated documentation of the targeted API endpoint and the list of accepted parameters defined there.\n\n## Response parsing\n\nWhen parsing the API responses take care to respect the [json](http://www.json.org/) or the [xml](https://www.w3.org/TR/REC-xml/) specifications. There are specific details associated with each one, for example, `json` format does not guarantee the order of name/value pairs in objects. Thus you should never depend on the order of properties when parsing `json` API responses.\n\nDepending 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.","excerpt":"","slug":"content-types","type":"basic","title":"Content Types"}
Infobip API supports several [content types](https://en.wikipedia.org/wiki/Media_type). Most of the API requests and responses will be either of `application/json` or `application/xml` type. You can find out more about the `json` format [here](http://www.json.org/), and `xml` [here](https://www.w3.org/TR/REC-xml/). Note that some API endpoints, like e-mail sending, use `multipart/form-data` so it is advisable to check the dedicated documentation page of your targeted endpoint for details. ## Specifying response content type You can specify the desired API response content type in one of two ways. ### Accept header First is through the usage of the standard [Accept](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept) HTTP header. For example a request: ``` GET /sms/1/reports HTTP/1.1 Host: api.infobip.com Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== Accept: application/json ``` will produce a `json` formatted response that might look like this: ```json { "results": [] } ``` ### Path extension If, for any reason you are unable to modify the Accept header of your API call then there is a second way of requesting a specific content type. To do that append the request path with the extension corresponding to the content type of your choosing. | content type | path extension | | --- | --- | | `application/json` | `.json` | | `application/xml` | `.xml` | For example, the request: ``` GET /sms/1/reports.xml HTTP/1.1 Host: api.infobip.com Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== ``` will result in response with the `xml` format that could look something like this: ```xml <?xml version='1.0' encoding='UTF-8'?> <reportResponse> <results/> </reportResponse> ``` ## Specifying request content type Content type of your request body data should be specified in the [Content-Type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type) header of the request. If not otherwise specified API endpoints will accept either `application/json` or `application/xml` types of content. [block:callout] { "type": "warning", "title": "Notice", "body": "It is mandatory to specify the Content-Type header for API requests that contain HTTP message body data. Typically those are requests using the POST and PUT HTTP methods." } [/block] For example, you can format the sms message in either `json` or `xml`, but are required to fill out the Content-Type header accordingly: [block:code] { "codes": [ { "code": "POST /sms/1/text/single HTTP/1.1\nHost: api.infobip.com\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\nContent-Type: application/json\n\n{\n \"to\":\"41793026727\",\n \"text\":\"Test SMS.\"\n}", "language": "json" }, { "code": "POST /sms/1/text/single HTTP/1.1\nHost: api.infobip.com\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\nContent-Type: application/xml\n\n<request>\n <to>41793026727</to>\n <text>Test SMS.</text>\n</request>", "language": "xml" } ] } [/block] 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 which, in a `multipart/form-data` format so another content type for the response is desirable: ```http 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 <jane.doe@somecompany.com> ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="to" john.smith@somedomain.com ------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 a `json` format. ## Bad request errors requests 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: [block:code] { "codes": [ { "code": "{\n \"requestError\": {\n \"serviceException\": {\n \"messageId\": \"BAD_REQUEST\",\n \"text\": \"Bad request\"\n }\n }\n}", "language": "json" }, { "code": "<?xml version='1.0' encoding='UTF-8'?>\n<ApiException>\n <requestError>\n <serviceException>\n <messageId>BAD_REQUEST</messageId>\n <text>Bad request</text>\n </serviceException>\n </requestError>\n</ApiException>", "language": "xml" } ] } [/block] This response can have several causes, here are a few of the common ones: * 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 with the dedicated documentation of the targeted API endpoint and the list of accepted parameters defined there. ## Response parsing When parsing the API responses take care to respect the [json](http://www.json.org/) or the [xml](https://www.w3.org/TR/REC-xml/) specifications. There are specific details associated with each one, for example, `json` format does not guarantee the order of name/value pairs in objects. Thus 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.