> This page is for Developers.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.emnify.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.emnify.com/_mcp/server.

# Set data quota

POST https://cdn.emnify.net/api/v1/endpoint/{endpoint_id}/quota/data
Content-Type: application/json

Required permissions Beta [Learn more](/developers/api-guidelines/permissions#how-permissions-work)`Endpoint.Quota.Data` + `Create`Roles: Administrator UserSets the data quota of an endpoint and replaces any existing data quota.
When `apply_data_quota` is enabled in the service profile, the device needs an `ACTIVE` quota with volume left to use data services.
A new `ACTIVE` quota takes effect as soon as the request succeeds.To top up a quota, retrieve the remaining volume, add the top-up volume, and send the sum as the new `volume`.
Send `threshold_percentage` again, or the earlier threshold volume stays in place.If you set `threshold_percentage`, the system generates a "Quota threshold reached" event when the remaining volume drops below it.
When the volume runs out, the system generates a "Quota used up" event and blocks the device from using data services.
Both events include the quota in their details.Since December 9, 2024, throttling isn't available as an action on quota exhaustion, and the API ignores the peak throughput parameter.
A request with `action_on_exhaustion.id` set to `2` fails with a 422 error.

Reference: https://docs.emnify.com/developers/api/endpoint/endpoint-quota-data-by-endpoint-id-post

## Authentication

- `Authorization` header (bearer token, required) — An `auth_token` should be provided to authenticate a session. To obtain an `auth_token`, see the [`/api/v1/authenticate` **POST** request](/developers/api/authentication/authenticate).

## Request

### Path parameters

- `endpoint_id` (integer, required) — Numeric ID of an endpoint

### Body (application/json)

This endpoint expects an EndpointDataQuotaRequest.

- `status` (EndpointQuotaStatusRequest, required) — Status to set for the quota. To let the device use the quota, set `id` to `1`.
- `volume` (float, required) — Volume of the quota in MB. To top up a quota, send the remaining volume plus the top-up volume.
- `expiry_date` (string, required) — When the quota expires, in UTC. After this time, the device can't use data services, even if volume remains. Use any future time to create a package of any length, such as 1 hour, 24 hours, or 7 days. Accepts `YYYY-MM-DD HH:MM:SS` or ISO 8601. The API ignores any time zone offset and always reads the time as UTC.
- `action_on_exhaustion` (EndpointQuotaActionOnExhaustionRequest, required) — What happens when the quota volume runs out.
- `auto_refill` (enum, optional) — Whether the quota refills daily with the last added volume. `0` disables auto-refill and `1` enables it. You can also send `false` or `true`. If you leave it out, a new quota has auto-refill disabled and an existing quota keeps its setting. A top-up also changes the refill volume, because the quota refills to the last `volume` you sent.
  - Allowed values: `0`, `1`
- `threshold_percentage` (integer, optional) — Percentage of `volume` below which the system generates a "Quota threshold reached" event. For example, `15` with a `volume` of 100 generates the event when less than 15 MB remain. If you leave it out, a new quota has no threshold and an existing quota keeps its earlier threshold volume, so include it in every top-up.

## Response

### 201

The data quota is set.

## Errors

### 400 Bad Request Error

The request fails for one of these reasons: - The `expiry_date` value can't be parsed. - A field has the wrong type, such as a `status.id` that isn't a number. The message names the field. - The `endpoint_id` isn't an integer.

- `status_code` (integer, required) — HTTP status code.
- `message` (string, required) — Error message.

### 401 Unauthorized Error

The request has no valid authentication token.

- `message` (string, required) — Error message.

### 403 Forbidden Error

Your role doesn't include the permission this endpoint requires. Most endpoints return `error_code`, `error_token`, and `message`. Some return only `status_code` and `message`.

- `error_code` (integer, optional)
- `error_token` (string, optional)
- `status_code` (integer, optional)
- `message` (string, optional)

### 422 Unprocessable Entity Error

The request fails for one of these reasons: - `action_on_exhaustion.id` is `2`, the decommissioned throttle action. - `expiry_date` is missing or isn't in the future. - `status`, `action_on_exhaustion`, or `volume` is missing, or an ID doesn't exist. The message is `Unprocessable Entity`. - The endpoint doesn't exist or isn't part of your organization. The message is `Unprocessable Entity`.

- `status_code` (integer, required) — HTTP status code.
- `message` (string, required) — Error message.

## Types

### EndpointQuotaStatusRequest

Status to set for the quota. To let the device use the quota, set `id` to `1`.

- `id` (enum, required) — ID of the quota status: - `1`: `ACTIVE` - `2`: `EXHAUSTED` - `3`: `EXPIRED`
  - Allowed values: `1`, `2`, `3`

### EndpointQuotaActionOnExhaustionRequest

What happens when the quota volume runs out.

- `id` (enum, required) — ID of the action on quota exhaustion. `1` (Block) is the only supported action, which blocks the device from using the service.
  - Allowed values: `1`

## Examples

**Request**

```json
{
  "status": {
    "id": 1
  },
  "volume": 100,
  "expiry_date": "2030-01-17 08:47:00",
  "action_on_exhaustion": {
    "id": 1
  },
  "auto_refill": 1,
  "threshold_percentage": 15
}
```

**Response**

```json
{}
```

**SDK Code**

```python Create a 100 MB Data Quota
import requests

url = "https://cdn.emnify.net/api/v1/endpoint/1/quota/data"

payload = {
    "status": { "id": 1 },
    "volume": 100,
    "expiry_date": "2030-01-17 08:47:00",
    "action_on_exhaustion": { "id": 1 },
    "auto_refill": 1,
    "threshold_percentage": 15
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript Create a 100 MB Data Quota
const url = 'https://cdn.emnify.net/api/v1/endpoint/1/quota/data';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"status":{"id":1},"volume":100,"expiry_date":"2030-01-17 08:47:00","action_on_exhaustion":{"id":1},"auto_refill":1,"threshold_percentage":15}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Create a 100 MB Data Quota
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://cdn.emnify.net/api/v1/endpoint/1/quota/data"

	payload := strings.NewReader("{\n  \"status\": {\n    \"id\": 1\n  },\n  \"volume\": 100,\n  \"expiry_date\": \"2030-01-17 08:47:00\",\n  \"action_on_exhaustion\": {\n    \"id\": 1\n  },\n  \"auto_refill\": 1,\n  \"threshold_percentage\": 15\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Create a 100 MB Data Quota
require 'uri'
require 'net/http'

url = URI("https://cdn.emnify.net/api/v1/endpoint/1/quota/data")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"status\": {\n    \"id\": 1\n  },\n  \"volume\": 100,\n  \"expiry_date\": \"2030-01-17 08:47:00\",\n  \"action_on_exhaustion\": {\n    \"id\": 1\n  },\n  \"auto_refill\": 1,\n  \"threshold_percentage\": 15\n}"

response = http.request(request)
puts response.read_body
```

```java Create a 100 MB Data Quota
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://cdn.emnify.net/api/v1/endpoint/1/quota/data")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"status\": {\n    \"id\": 1\n  },\n  \"volume\": 100,\n  \"expiry_date\": \"2030-01-17 08:47:00\",\n  \"action_on_exhaustion\": {\n    \"id\": 1\n  },\n  \"auto_refill\": 1,\n  \"threshold_percentage\": 15\n}")
  .asString();
```

```php Create a 100 MB Data Quota
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://cdn.emnify.net/api/v1/endpoint/1/quota/data', [
  'body' => '{
  "status": {
    "id": 1
  },
  "volume": 100,
  "expiry_date": "2030-01-17 08:47:00",
  "action_on_exhaustion": {
    "id": 1
  },
  "auto_refill": 1,
  "threshold_percentage": 15
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp Create a 100 MB Data Quota
using RestSharp;

var client = new RestClient("https://cdn.emnify.net/api/v1/endpoint/1/quota/data");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"status\": {\n    \"id\": 1\n  },\n  \"volume\": 100,\n  \"expiry_date\": \"2030-01-17 08:47:00\",\n  \"action_on_exhaustion\": {\n    \"id\": 1\n  },\n  \"auto_refill\": 1,\n  \"threshold_percentage\": 15\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Create a 100 MB Data Quota
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "status": ["id": 1],
  "volume": 100,
  "expiry_date": "2030-01-17 08:47:00",
  "action_on_exhaustion": ["id": 1],
  "auto_refill": 1,
  "threshold_percentage": 15
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://cdn.emnify.net/api/v1/endpoint/1/quota/data")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```