Ledger set data example

Hello,

I am trying to update the data in a device-scoped Ledger and running into issues. I'm following the API docs at: Cloud API reference | Reference Documentation | Particle

I'm doing this in Python but trying the curl commands as well. The curl command and Python equivalent I'm trying are:

curl -i -X PUT "https://api.particle.io/v1/orgs/MY_ORG/ledgers/MY_LEDGER/instances/MY_DEVICE_ID" \
       -H "Authorization: Bearer MY_API_TOKEN" \
       --data @data.json

where data.json contains what my Ledger data has and what I want to update it to:

{
    "test_var": true,
    "test_var_2": 20
}

However the response that comes back is:

{"ok":false,"error_description":"Body JSON was not in the correct format! missing field `instance` at line 1 column 54"}

Can someone please provide a sample JSON payload for what the data is supposed to look like? If I wrap the JSON Ledger data.json in an instance to look like:

{
  "instance": {
    "test_var": true,
    "test_var_2": 20
  }
}

then I still get back

{"ok":false,"error_description":"Body JSON was not in the correct format! missing field `instance` at line 1 column 74"}

So what should the data.json actually contain for my example?

Thank you

I figured it out, the data.json should look like

{"instance":{"data":{"test_var": false, "test_var2":20}}}

But what's missing from the docs is the curl command should also include the MIME type header in the request.

-H 'Content-Type: application/json' \ should be added to the curl example to look like this in the docs:

$ curl -X PUT "https://api.particle.io/v1/orgs/:orgSlugOrId/ledgers/:ledgerName/instances/:scopeValue" \
       -H "Authorization: Bearer :access_token" \
       -H 'Content-Type: application/json' \
       --data @data.json

With those changes, I get a 201 response back and the Ledger data is updated properly.

2 Likes

Thank you for updating us with the solution!