# Deploy Update

## Deploy update

<mark style="color:green;">`POST`</mark> `https://api.connect.jfrog.io/v2/deploy_update`

Using this call, you can deploy update flows on your devices. This is useful for CI/CD integrations and when you would like to deploy updates on your device fleet automatically.

#### Request Body

| Name                      | Type   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| ------------------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| user\_token               | string | This is your account token. Can be found under the Settings category on Connect dashboard.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| flow\_id                  | string | This is the id of the update flow you created on Connect dashboard. You can find it at the `Updates` category under the `Update Flows` tab.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| devices\_filter           | object | <p>A JSON object with the filter you would like to apply on your devices fleet. This filter will be applied and the result will be the devices that receive this update. The object has multiple keys: <br><strong>1.</strong> <code>"project": {"name": "\<project\_name>"}</code> set the <code>\<project\_name></code> as your project name from Connect dashboard. The <code>project</code> key <strong>must</strong> exist and the value of it is a JSON with the key <code>name</code>. <br><strong>2.</strong> <code>"groups": \[{"name": "\<group\_name>"}]</code> set the <code>\<group\_name></code> as a group name from Connect dashboard.  The <code>groups</code> key is a <strong>must</strong> key but the value of it can be an empty list. The value of it is a <code>list</code> of <code>JSON</code> objects each has a key called <code>name</code>. If multiple groups exist, all devices within those groups will receive the update.<br><strong>3.</strong> <code>"filters": \[{"type": "\<filter\_type>", "operand": "\<operand>", "value": "\<value>"}]</code> the filters key lets you add custom filters. Set the <code>\<type></code> key as the type of the filter (possible types can be found under this form). Set the <code>\<operand></code> key as the operand for this filter (possible operands can be found under this form). Set the <code>\<value></code> key as the value for this filter (the value depends on the type of the filter, examples can be found under this form).<br><br>You can set multiple filters, if you do so, they will all be applied on top of each other (examples can be found under this form). The <code>filters</code> key is a <strong>must</strong> key but the value of it can be an empty list.</p> |
| parameters\_mapping       | String | <p>Defines the update parameters values that are configured in the update flow.</p><p><code>"update\_param\_name": "value",</code></p><p><code>"update\_param\_name2": "value",</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| deployment\_configuration | String | A JSON object that defines the configuration that will be deployed with the update.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| comment                   | String | Set the `<comment>` as the comment for that deployment. The value of this key is a String.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| app                       | String | `"app": {"name": "<app_name>", "version": "<app_version>"}` Set the `<app_name>` as the name of the app you created on Connect dashboard. Set the `<app_version>` as the version for this app. Devices that will deploy the update successfully, their app version will change to the `app_version` you set here.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |

{% tabs %}
{% tab title="201: Created  Successfully created the deployment" %}

```json
{"message": "Created"}
```

{% endtab %}

{% tab title="400 Error occurred." %}

```
{"error_message": "<ERROR_MESSAGE>"}
```

{% endtab %}

{% tab title="429 Rate limit reached." %}

```
{}
```

{% endtab %}
{% endtabs %}

**Possible types and values:**

* **`devices_filter`** objec&#x74;**:**
  * **`filters`** key:&#x20;
    * Possible values for the `type` key:
      * `specific_device` - Set this value if you want to filter one specific device. The value of the  `value` key of this type is the ID of the device you want to filter (you can obtain the id on Connect dashboard). The possible `operand` key values for this type are: `is`, `is_not`
      * `tag` - Set this value if you want to filter devices by a tag. The value of the `value` key of this type is the name of the tag you want to filter (you can obtain the tag name on Connect dashboard). The possible `operand` key values for this type are: `is`, `is_not`
      * `app` - Set this value if you want to filter devices by the apps that are set to them. The value of the `value` key of this type is the app name. The possible `operand` key values for this type are: `is`, `is_not`. Additionally, you can set an `app_version` property to filter to a specific app version.
      * `device_state` - Set this value if you want to filter devices by their state. The possible values of the `value` key of this type are: `online`, `offline`.  The possible `operand` key value of this type is: `is`&#x20;
      * `deployment` - Set this value if you want to filter devices by the `deployment_id` and deployment status. The possible values for `value` are `pending`, `in_progress`, `success`, `failed`, `aborted`, `any`. You must set the `deployment_id` property with the value from the deployments table on the platform.

{% hint style="warning" %}
All values must be of type: **`String`**.
{% endhint %}

**Full payload example:**&#x20;

```json
{
  "user_token": "<user token>",
  "device_filter": {
    "project": { "name": "Demo" },
    "groups": [{ "name": "TestGroup1" }, { "name": "TestGroup2" }],
    "filters": [
      { "type": "specific_device", "operand": "is", "value": "d-4ec7-1be9" },
      { "type": "deployment", "deployment_id": "dp-9yl3-9ch7", "operand": "is", "value": "failed" }
    ]
  },
  "deployment_configuration": {
    "flow_id": "f-dd0c-73b9",
    "comment": "test webhook 1",
    "app": { "name": "default_app", "version": "v1.1" },
    "parameters_mapping": {
      "username": "ubuntu",
      "conf_path": "/etc/app/settings.conf"
    }
  }
}
```

#### Code Example

{% tabs %}
{% tab title="Python" %}

```python
import json
import requests

#Upswift tokens
user_token = "<user token>"

json_content = {
    "user_token": user_token,
    "device_filter": {
      "project": { "name": "Demo" },
      "groups": [{ "name": "TestGroup1" }, { "name": "TestGroup2" }],
      "filters": [
        { "type": "specific_device", "operand": "is", "value": "d-4ec7-1be9" },
        { "type": "deployment", "deployment_id": "dp-9yl3-9ch7", "operand": "is", "value": "failed" }
      ]
    },
    "deployment_configuration": {
      "flow_id": "f-dd0c-73b9",
      "comment": "test webhook 1",
      "app": { "name": "default_app", "version": "v1.1" },
      "parameters_mapping": {
        "username": "ubuntu",
        "conf_path": "/etc/app/settings.conf"
      }
    }
  }
                                
                             
                
call_request = requests.post("https://api.connect.onprem/v2/deploy_update", json=json_content)
call_response = json.loads(call_request.text)

if call_request.status_code != 200:
    if call_request.status_code == 429:
        error = "API limit reached"
    else:
        error = call_response["error_message"]
    print(error)
else:
    response_message = call_response["message"]
```

{% endtab %}
{% endtabs %}
