Downlink message format (v3)

Hello all,
I’m having issues sending downlink messages to a v3 application. I’m testing using curl:

  curl --location \
  --header 'Authorization: Bearer NNSXS.BD7UVBPG4HDEGX3C2..etc' \
  --header 'Content-Type: application/json' \
  --request POST \
  --data '{"downlink_message":[{
      "decoded_payload":{"state1":"false"},
      "f_port":1,
      "priority":"NORMAL"
    }]
  }' \
  'https://eu1.cloud.thethings.network/api/v3/as/applications/heltec-esp32-otaa-led1/webhooks/testhook2/devices/22(redacted)909/down/push'

But it results in no response (error or success) from the TTN stack & no live data displayed.

My downlink formatter:

function encodeDownlink(input) {
  // Input is a string true or false
  var states = ["false", "true"];
  return {
    bytes: [states.indexOf(input.data.state1)],
    fPort: input.fPort,
    warnings: [],
    errors: []
  };
}

function decodeDownlink(input) {
  return {
    data: {
      state1: ["false", "true"][input.bytes[0]]
    },
    warnings: [],
    errors: []
  }
}

I’ve had previous success with the V2 format but no making much headway here. I note the V2 docs had a curl example but the V3 doesn’t, if I get this working I might submit a pull request to include a working example.

Thanks for looking,

Should be:

--data '{"downlinks":[{

should be:

"decoded_payload": {"data": {"state1":"false"}},

If you want to add the port in, it would be simplest to add it to the data object.

See the documentation, both Getting Started and Reference, linked bottom right of the console, for details, like the curl example you were looking for:

https://www.thethingsindustries.com/docs/getting-started/api/#schedule-downlink

1 Like

Nick ,

Many thanks for the reply & pointing out the location of the reference. For others I can confirm that the following works with my payload formatter as per my original post.

  curl --location \
  --header 'Authorization: Bearer NNSXS.<your downlink api key>' \
  --header 'Content-Type: application/json' \
  --header 'User-Agent: my-integration/my-integration-version' \
  --request POST \
  --data '{
    "downlinks": [{
      "decoded_payload": {"data": {"state1":"false"}},
      "f_port": 1,
      "priority":"NORMAL"
    }]
  }' \
 'https://eu1.cloud.thethings.network/api/v3/as/applications/heltec-esp32-otaa-led1/webhooks/testhook2/devices/22......9909/down/push'

Regards,

1 Like

Your welcome - as the solution to the problem was provided by me, perhaps my response should be the solution, I did the thinking so you could CopyNPasta & test :grin:

1 Like

Sure, no problem.