Curl request in webhook

I am trying to get this curl request in a webhook.

$ curl -X GET "https://www.openfood.ch/api/v3/products?barcodes=7610046125730" -H 'Content-Type: application/vnd.api+json' -H 'Accept: application/json' --compressed -H 'Authorization: Token token="API_KEY"'

What do i have to do?

Hi @Xeb0n,

I haven’t tested this, but I imagine it’d be something like this:

 {
      "event": "your_event",
      "url": "https://www.openfood.ch/api/v3/products",
      "requestType": "GET",
      "headers": {
      	"Authorization": "Token token=\"API_KEY\"",
      	"Content-Type": "application/vnd.api+json"
      },
      "query": {
      	"barcodes": "7610046125730"
      }
    }

Thanks,
David

3 Likes

Thank you very much it worked perfectly!

I actually ran into a new problem, the Particle subscription to the hook is not working.
When receiving something from the webhook the Particle doesn’t respond. When sending the same Event Name and Data through the Publish event feature in the api it works fine.

My code:

void setup() {

    Particle.subscribe("hook-response/testopen", myHandler);
    pinMode(7,OUTPUT);
    digitalWrite(7,HIGH);
    delay(2000);
    digitalWrite(7,LOW);
    Particle.publish("testopen", "7610046125730");
}

void loop() {
    Particle.process();
}

void myHandler(const char *event, const char *data)
{
  digitalWrite(7, HIGH);
  String dataIn = String(data);
  Particle.publish("Response");
  delay(1000);
  digitalWrite(7,LOW);
}

You should publish PRIVATE and you should not use delay() in the handler.
Try setting the source device to ANY in the webhook and the subscription to MY_DEVICES.

What is the point of String dataIn = String(data)?

2 Likes