Webhooks Issue with Custom Header

I am attempting to use Particle Webhooks with Carriots, a data logging service. Carriots requires the user to POST data using an API key in the header (carriots.apikey). I have been unable to create the web hook with a period in the header name.

This is the JSON file that does not work:

{
    "eventName": "webhookevent",
    "url": "http://api.carriots.com/streams/",
    "requestType": "POST",
    "headers": {
        "carriots.apikey": "xxxxxxxxxxx"
    },
    "json": {
        "protocol":"v1",
        "at":1355837673,
        "device":"device@xxx",
        "data": {
            "temp":"21",
            "hum":"58"
        }
    }
}

It gives the output:

Sending webhook request  { uri: '/v1/webhooks',
  method: 'POST',
  json: 
   { event: 'webhookevent',
     url: 'http://api.carriots.com/streams/',
     deviceid: undefined,
     requestType: 'POST',
     mydevices: true,
     eventName: 'webhookevent',
     headers: { 'carriots.apikey': 'xxxxxxxxxxx' },
     json: 
      { protocol: 'v1',
        at: 1355837673,
        device: 'device@xxx',
        data: [Object] } },
  headers: { Authorization: 'Bearer xxxxxxx' } }
Error {}

However, if I just delete the period in ‘carrots.apikey’,

{
    "eventName": "webhookevent",
    "url": "http://api.carriots.com/streams/",
    "requestType": "POST",
    "headers": {
        "carriotsapikey": "xxxxxxxxxxx"
    },
    "json": {
        "protocol":"v1",
        "at":1355837673,
        "device":"device@xxx",
        "data": {
            "temp":"21",
            "hum":"58"
        }
    }
}

the web hook is accepted:

Sending webhook request  { uri: '/v1/webhooks',
  method: 'POST',
  json: 
   { event: 'webhookevent',
     url: 'http://api.carriots.com/streams/',
     deviceid: undefined,
     requestType: 'POST',
     mydevices: true,
     eventName: 'webhookevent',
     headers: { carriotsapikey: 'xxxxxxxxxxx' },
     json: 
      { protocol: 'v1',
        at: 1355837673,
        device: 'device@xxx',
        data: [Object] } },
  headers: { Authorization: 'Bearer xxxxxxx' } }
Successfully created webhook with ID xxxxxxxx

I tried encoding the period (i.e. carrots\u002eapikey), but I still got the same error. Any ideas on how to get webhooks to work with carriots.com?

Did you ever figure out what was wrong?

The header name in a HTTP header cannot contain a period or dot. What's sort of interesting is that it's commonly believed that headers name can only be a-z, A-Z, 0-9, -, and _, as mentioned here which was the answer in the box at the top of Google when I queried.

However if you look closer at RFC7230 it does appear that the header name is a token which is more relaxed and can contain a period.

In any case, you can't enter one because it appears to be restricted as part of the data sanitization in the webhook engine.

Tangentially related, you can't have a JSON key with a period in mustache templates because dot is the separator for arrays and embedded objects, so that will also cause a different problem.

1 Like