Hi,
i can’t figure out how to use a particle.variable in a webhook.
The variable is stored from code to the cloud and can be read with CLI command.
Is it possible to use particle.variable() in a webhook ?
I need this since my bearer key is way above 255 but less than 622 chars long
here is the webhook:
{
"eventName": "event",
"url": "https://URL",
"requestType": "POST",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer {{AccessToken}}",
"Host": "HOST"
},
"form": {
"description": "{{description}}",
},
"mydevices": true
}
And here is the code in build:
String AccessToken;
void setup() {
// particle serial monitor
Serial.begin(115200);
Particle.variable("AccessToken", AccessToken);
// Lets listen for the hook response
Particle.subscribe("hook-response/webhook", gotData, MY_DEVICES);
// Lets give ourselves 10 seconds before we actually start the program.
// That will just give us a chance to open the serial monitor before the program sends the request
for(int i=0;i<10;i++) {
Serial.println("waiting " + String(10-i) + " seconds before we publish");
delay(1000);
}
// Let's request the weather, but no more than once every 60 seconds.
Serial.println("Requesting Access token!");
// publish the event that will trigger our Webhook
Particle.publish("webhook", NULL, 60, PRIVATE);
}
int functionXYZ(String xyz) {
Particle.publish("webhook", NULL, 60, PRIVATE);
}
void loop() {
}
// This function will get called when weather data comes in
void gotWeatherData(const char *name, const char *data) {
String str = String(data);
AccessToken = tryExtractString(str, "access_token\":\"","\",\"token_type\"");
Serial.println("Received Bearer key: \"" + AccessToken + "\"");
Particle.publish("event", "{ \"description\": \"TESTING-LIKE-NEVER-BEFORE\" }", 60, PRIVATE);
}