> ## Documentation Index
> Fetch the complete documentation index at: https://help.pelion.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Worked example of an API call

> Follow a step-by-step example that edits a monitoring alert using the Pelion Portal API.

This example shows how to edit a monitoring alert using the Portal API. The call updates the alert's lower and upper usage thresholds by sending a `PATCH` request to the `/alerts/{id}` endpoint.

> [!NOTE]
>
> This example uses [cURL](https://curl.se/) from the command line. You can also use an API client such as [Postman](https://www.postman.com/). A browser's address bar is not suitable, because it can only send `GET` requests and cannot add an `Authorization` header.

## View the reference documentation

The [API Reference](https://connectivity-eu.pelion.com/api-reference/) describes the endpoints in the API, what they are used for, and the mandatory and optional information to include in your calls.

## Create an access key

The Portal API uses access keys to validate that calls come from permitted sources. Before you start, create an access key and copy it to a secure location.

> [!NOTE]
>
> For instructions, see [Authenticate API calls](https://help.pelion.com/api/authentication.md).

## Add parameters

In this example, for the `/alerts/{id}` endpoint, the path parameter is `{id}`.

The [reference documentation](https://connectivity-eu.pelion.com/api-reference/) for this endpoint shows that you must include the `id` of the alert that you want to edit. If you do not include this mandatory parameter, the call results in an error.

To include a parameter in your request, replace the braces and the placeholder inside them with an actual value. For example, if the unique identifier of the monitoring alert you want to edit is `24`, the request URL is:

```bash theme={null}
curl -X PATCH "https://connectivity-eu-api.pelion.com/alerts/24"
```

> [!TIP]
>
> If you do not know the monitoring alert's unique identifier, retrieve it by making a `GET` request to the `/alerts` endpoint.

> [!NOTE]
>
> For more information about parameters, see [Add path parameters](https://help.pelion.com/api/path-parameters.md).

## Add a request body

The [reference documentation](https://connectivity-eu.pelion.com/api-reference/) for this endpoint shows that you must provide a request body. The request body sets the monitoring alert's new lower and upper usage thresholds, in bytes.

The following request body sets the lower threshold to 500 KB (`512000` bytes) and the upper threshold to 1 MB (`1048576` bytes):

```json theme={null}
{
  "lowerThreshold": "512000",
  "upperThreshold": "1048576"
}
```

The following example shows the request once you add the `id` parameter and the request body:

```bash theme={null}
curl -X PATCH "https://connectivity-eu-api.pelion.com/alerts/24" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{"lowerThreshold": "512000", "upperThreshold": "1048576"}'
```

> [!NOTE]
>
> For more information about request bodies, see [Add a request body](https://help.pelion.com/api/request-bodies.md).

## Add your access key

To validate that you have permission to access the Portal API, include your access key as a Bearer token in the `Authorization` header.

The following example shows the complete call with the path parameter, request body, and access key. Replace `YOUR_ACCESS_KEY` with your own access key:

```bash theme={null}
curl -X PATCH "https://connectivity-eu-api.pelion.com/alerts/24" \
  -H "Authorization: Bearer YOUR_ACCESS_KEY" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -d '{"lowerThreshold": "512000", "upperThreshold": "1048576"}'
```

> [!NOTE]
>
> For more information about access keys, see [Authenticate API calls](https://help.pelion.com/api/authentication.md).

## Interpret the response

If the call succeeds, the endpoint returns a response code in the `2xx` range and a response body containing the updated monitoring alert.

The following example shows how the response body might look:

```json theme={null}
{
  "contents": [
    {
      "id": "24",
      "ruleType": "sim",
      "target": "447000000001",
      "lowerThreshold": "512000",
      "upperThreshold": "1048576",
      "dateCreated": "2018-02-11T10:33:30.000Z"
    }
  ]
}
```

The response body contains:

* The `id` field, which contains the monitoring alert's unique identifier.
* The `ruleType` field, which contains the type of alert.
* The `target` field, which identifies the SIM to which the monitoring alert applies.
* The `lowerThreshold` field, which contains the lower usage threshold, in bytes, at which the alert is triggered.
* The `upperThreshold` field, which contains the upper usage threshold, in bytes, at which the alert is triggered.
* The `dateCreated` field, which contains the date and time at which the alert was created.

If the call fails, check the response code. A `4xx` code usually means a problem with your request, such as an invalid alert `id` or a missing permission.

> [!NOTE]
>
> For more information about handling API responses, see [Handle responses](https://help.pelion.com/api/handle-responses.md) and [Response and error codes](https://help.pelion.com/api/response-codes.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.