# Deployments created via REST are not discovered by device

**URL:** <https://hub.mender.io/t/deployments-created-via-rest-are-not-discovered-by-device/6509>\
**Category:** General Discussions\
**Tags:** mender-client, deployment, rest\
**Created:** [January 24, 2024, 5:29pm UTC](https://hub.mender.io/t/deployments-created-via-rest-are-not-discovered-by-device/6509 "2024-01-24T17:29:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![donasmi](https://avatars.discourse-cdn.com/v4/letter/d/e68b1a/32.png) [@donasmi](https://hub.mender.io/u/donasmi)\
**Post date:** [January 24, 2024, 5:29pm UTC](https://hub.mender.io/t/deployments-created-via-rest-are-not-discovered-by-device/6509/1 "2024-01-24T17:29:52Z")

</div>

Hi there,

I use a REST call to create a deployment for a specific device ID. When I `sudo mender check-update` on my device to force the client to check for a server update, I see that the deployment status is updated to `pending`, but the device does not seem to find any update info, and thus cannot be updated.

If I create a deployment for the same device and artifact using the GUI, after `sudo mender check-update`ing on the device the deployment immediately jumps into ‘inprogress’ and awaits user confirmation.

This used to work when creating a deployment via REST before the major bump. Has something changed on this front? Has anyone experienced a similar issue?

Many thanks!

---

<div class="post-metadata">

**Author:** ![TheYoctoJester](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/theyoctojester/32/1444_2.png) [@TheYoctoJester](https://hub.mender.io/u/TheYoctoJester)\
**Post date:** [January 24, 2024, 5:46pm UTC](https://hub.mender.io/t/deployments-created-via-rest-are-not-discovered-by-device/6509/2 "2024-01-24T17:46:07Z")

</div>

Hi @donasmi,

I’m not aware of any issues here, recently used this very mechanism.  
Which “major version” bump are you referring to? There should not have been anything that affects this. The `sudo mender` invocation suggests that this is a debianoid image on Mender Client 3.X, but can you please give a few more details? Eventually check the logs?

Greets,  
Josef

---

<div class="post-metadata">

**Author:** ![donasmi](https://avatars.discourse-cdn.com/v4/letter/d/e68b1a/32.png) [@donasmi](https://hub.mender.io/u/donasmi)\
**Post date:** [January 24, 2024, 5:56pm UTC](https://hub.mender.io/t/deployments-created-via-rest-are-not-discovered-by-device/6509/3 "2024-01-24T17:56:11Z")

</div>

Thanks for responding so quickly!  
We are using mender client 3.5.2.  
I checked the journal and it doesn’t really give me a lot of info. For the deployment that I create via REST, I see the following once I force check for an update on the server:

```auto
Jan 24 17:53:30 x mender[6861]: time="2024-01-24T17:53:30+01:00" level=info msg="Forcing state machine to: update-check"
Jan 24 17:53:30 x mender[6861]: time="2024-01-24T17:53:30+01:00" level=info msg="State transition: check-wait [Idle] -> update-check [Sync]"
Jan 24 17:53:30 x mender[6861]: time="2024-01-24T17:53:30+01:00" level=info msg="State transition: update-check [Sync] -> check-wait [Idle]"
Jan 24 17:59:03 x mender[6861]: time="2024-01-24T17:59:03+01:00" level=info msg="State transition: check-wait [Idle] -> inventory-update [Sync]"
Jan 24 17:59:04 x mender[6861]: time="2024-01-24T17:59:04+01:00" level=info msg="State transition: inventory-update [Sync] -> check-wait [Idle]"
Jan 24 17:59:05 x mender[6861]: time="2024-01-24T17:59:05+01:00" level=info msg="State transition: check-wait [Idle] -> update-check [Sync]"
Jan 24 17:59:05 x mender[6861]: time="2024-01-24T17:59:05+01:00" level=info msg="State transition: update-check [Sync] -> check-wait [Idle]"

```

But maybe I create the deployment incorrectly?  
This is my rest call to deploy one artifact to one device ID:

```auto
headers = _authenticate(
        {
            "Content-Type": "application/json",
            "Accept": "application/json",
        }
    )
    data = {
        "name": "production",
        "artifact_name": f"{artifact_name}",
        "devices": [f"{device_id}"],
        "phases": [],
        "retries": 0,
    }

    response = requests.post(
        f"{MENDER_SERVER_URI}/api/management/v1/deployments/deployments",
        json=data,
        headers=headers,
    )

```

Does this seem right?

---

<div class="post-metadata">

**Author:** ![TheYoctoJester](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/theyoctojester/32/1444_2.png) [@TheYoctoJester](https://hub.mender.io/u/TheYoctoJester)\
**Post date:** [January 25, 2024, 11:33am UTC](https://hub.mender.io/t/deployments-created-via-rest-are-not-discovered-by-device/6509/4 "2024-01-25T11:33:05Z")

</div>

Hi @donasmi,

Looks about right, indeed. My code is slightly different (and also, JS), but the key parts are:

```auto
const artifact_name = "...";
const device_id = "...";
const token = "...";
const req = {
  method: "POST",
  url: "https://hosted.mender.io/api/management/v1/deployments/deployments",
  headers: {
    'Accept': 'application/json', 
    'Authorization': 'Bearer ' + token,
    'Content-Type': 'application/json'
  },
  {
    data: {
    name: device_id,
    artifact_name: artifact_name,
    devices: [
      device_id
    ],
    all_devices: false
  }
};

axios(req)
.then((response) => {
...
})
.catch((error) => {
...
})

```

Maybe setting the empty `phases` property is getting into the way here, but that’s really just guessing.

Greets,  
Josef

---

<div class="post-metadata">

**Author:** ![donasmi](https://avatars.discourse-cdn.com/v4/letter/d/e68b1a/32.png) [@donasmi](https://hub.mender.io/u/donasmi)\
**Post date:** [January 25, 2024, 11:40am UTC](https://hub.mender.io/t/deployments-created-via-rest-are-not-discovered-by-device/6509/5 "2024-01-25T11:40:26Z")

</div>

Hi @TheYoctoJester ,

Indeed, I removed “phases” and added all\_devices: false, and now the deployment is picked up and the device can be upgraded.

Thank you so much for your support! 🙏

---

<div class="post-metadata">

**Author:** ![bradley](https://avatars.discourse-cdn.com/v4/letter/b/c37758/32.png) [@bradley](https://hub.mender.io/u/bradley)\
**Post date:** [August 15, 2024, 5:53pm UTC](https://hub.mender.io/t/deployments-created-via-rest-are-not-discovered-by-device/6509/6 "2024-08-15T17:53:05Z")

</div>

Hi Josef! Do you have to specify `'name': 'device_id'`? From the NewDeployment scheme in the Mender API [docs](https://docs.mender.io/api/#management-api-deployments-schemas-newdeployment), I inferred that this should be free-form? But I might have missed something.

I ask, because I am noticing that I also have to set the `name` field to the `device_id` in order to get the deployment created successfully.
