GuidesAPI Requests
HTTP Headers
When interacting with the Mist API, it is important to include specific HTTP headers in your requests. These headers ensure proper communication, authentication, and data formatting between your client and the Mist Cloud platform.
Below is a summary of the required and recommended headers, along with explanations for each:
Required Headers
-
Content-Type: application/json (or multipart/form-data for file uploads)
- Indicates the format of the data in the body of your request.
- Use
application/jsonfor requests with a JSON payload (such as POST, PUT, or PATCH). - Use
multipart/form-datawhen uploading files to the API.
-
Accept: application/json, application/vnd.api+json
- Specifies the response format(s) your client can handle.
application/jsonis sufficient for most use cases.- It is recommended to also include
application/vnd.api+jsonto enable Mist Cloud to compress large responses, which is especially useful for organizations with many resources.
Conditional Header
-
Authorization: Token {APITOKEN}
- Used to authenticate your requests with the Mist API.
- Replace
{APITOKEN}with your actual API token. - This header is required for all requests when using API token authentication.
- Example:
Authorization: Token 1234567890abcdef
-
X-CSRFToken: {csrftoken_value_from_cookie}
- Required only if you are authenticating using a username and password (login/password).
- The value should be taken from the
csrftokencookie provided by the Mist Cloud after login. - This header helps protect against Cross-Site Request Forgery (CSRF) attacks.
Example Request
GET /api/v1/sites HTTP/1.1
Host: api.mist.com
Content-Type: application/json
Accept: application/json, application/vnd.api+json
Authorization: Token {your_api_token}
X-CSRFToken: {csrftoken_value_from_cookie} # Only if using login/passwordNotes
- The
AuthorizationorX-CSRFTokenheaders are mandatory when using an API token for authentication. Without it, your requests will be rejected. - If you are using an API token for authentication, the
X-CSRFTokenheader is not required. - Always ensure your
Content-TypeandAcceptheaders are set correctly to avoid errors or unexpected responses. - Including
application/vnd.api+jsonin theAcceptheader is recommended for better performance with large datasets.