Webhook to FIWARE


#1

Dear Particle-Community!

I am having trouble customizing the webhooks to work with a FI-Ware Contextbroker (see: context Broker Programmer Guide ). My Contextbroker expects the following json body in a POST request:

{
  "contextElements":
    [
      {
        "type":"Producer",
        "isPattern":"false",
        "id":"1234",
        "attributes":
          [
            {
              "name":"currentProduction",
              "type":"float",
              "value":"4321"
            },
            {
              "name":"timestamp",
              "type":"int",
              "value":"123456789"
            }
          ]
      }
    ],
  "updateAction":"UPDATE"
}

somehow the webhook adds the following fields:

{
  "event": "{{SPARK_EVENT_NAME}}",
  "data": "{{SPARK_EVENT_VALUE}}",
  "published_at": "{{SPARK_PUBLISHED_AT}}",
  "coreid": "{{SPARK_CORE_ID}}"
}

to every call. Thus the messages I am sending look like this (I have defined a custom variable "CURRENT_PRODUCTION) :

{
  "event":"ProductionReport",
  "data":"{ \"CURRENT_PRODUCTION\": \"0\" }",
  "published_at":"123456789",
  "coreid":"123456789abcddefghi",
  "contextElements":
    [
      {
        "type":"Producer",
        "isPattern":"false",
        "id":"1234",
        "attributes": [
          {
            "name":"currentProduction",
            "type":"float",
            "value":"4321"
          },
          {
            "name":"timestamp",
            "type":"int",
            "value":"123456789"
          }
        ]
      }
    ],
  "updateAction":"UPDATE"
}

The values change in a correct manner - that’s all fine. I just want to get rid of the first four variables (event, data, published_at, coreid), which are added by the webhook. How could I achieve this?

To give it a quick fix I am calling a PHP function on my web server, which “translates” the data into a correct HTTP POST Request to the Context Broker. As this will create a lot of load on my server, as soon as the amount of devices scales up, I’d like to establish a direct connection.

Any help would be appreciated! :smiley:

Thanks!

Tobi


I’ve edited your post to properly format the code. Please check out this post, so you know how to do this yourself in the future. Thanks in advance! ~Jordy


#2

@Duesentrieb, take a look at this topic. I believe it applies to your webhook. @Dave, here is another “extra” webhook payload issue!


#3

Thanks for the heads up! Sounds like we should definitely add a “raw” type option for avoiding folding in these default fields. :slight_smile:

Thanks!
David


#4

@Jordy: Thanks for the advice regarding the formatting! I’ll keep that in mind for the next time!

@peekay123 - I read the thread you linked - but sadly only the first few posts. It’s exactly the same issue - the FIWARE Server get’s mixed up by the extra payload. Therefore the “raw” type option would be a great relief for us. I guess we can close this topic and continue in the “Webhooks & Parse.com” thread. Thanks for the quick advice!