I've created a Webhook in IFTTT to have my server send me notifications to my Android phone based on events. For some reason, the values aren't passed along in the web request. Looking in the Webhooks documentation it says:
To trigger an Event with 3 JSON values
Make a POST or GET web request to:
https://maker.ifttt.com/trigger/{event}/with/key/{MyKey}
With an optional JSON body of:
{ "value1" : "", "value2" : "", "value3" : "" }
The data is completely optional, and you can also pass value1, value2, and value3 as query parameters or form variables. This content will be passed on to the action in your Applet.
The event is set up to display Your test value is {{value1}}
:
I then try to run this in Powershell:
$WebhookURL = "https://maker.ifttt.com/trigger/{MyEvent}/json/with/key/{MyKey}
Invoke-RestMethod -Method Get -Uri $($WebhookURL+"?value1=TESTVALUE") -ContentType "application/json"
However, this sends a notification to my phone that says, literally, Your test value is {{value1}}
:
So the notification is correctly fired, it's just that the value for "value1" isn't passed along properly. I've also tried to pass the value as the -Body
but it's the same result:
$Body = @{
value1 = "TESTVALUE"
}
Invoke-RestMethod -Method Get -Uri $WebhookURL -Body $Body -ContentType "application/json"
Passing the $Body
value to ConvertTo-Json -Compress
makes the request fail with HTTP Error 403: Bad Request
so it's not that either. Essentially, I'm doing exactly like this other Stack post suggests but it's not passing the value. What could be the problem here?
UPDATE: I also tried the following as suggested by Mathias:
$Body = @{
value1 = "TESTVALUE"
} | ConvertTo-Json -Compress
Invoke-RestMethod -Method Post -Uri $WebhookURL -Body $Body -ContentType "application/json"
But the result is the same. I also tried adding value2 and value3 with empty strings to the Body but the result is the same. I tried using and not using -Compress
but the result is the same, using and not using quotation marks around value1 doesn't change anything:
UPDATE2: Using Curl just straight up throws an error:
curl -X POST https://maker.ifttt.com/trigger/MyEvent/json/with/key/MyKey -H "Content-Type: application/json" -d '{"value1": TESTVALUE}'
{"errors":[{"message":"Unexpected token v in JSON at position 1"}]}
I also tried running the Powershell Invoke-RestMethod
with -UseDefaultCredentials
but the result is the same.
UPDATE3: The IFTTT logs show that the value for Value1 is not passed on, so something must be wrong with the request:
Workaround: don't use Invoke-RestMethod
and instead use Curl:
$WebhookURL = "https://maker.ifttt.com/trigger/MyEventName/with/key/MyKey"
$Command = 'curl -X POST -H "Content-Type: application/json" -d "{""value1"":""' + $VariableWithMyValueHere + '"",""value2"":""Test2"",""value3"":""Test3""}" ' + $WebhookURL
cmd.exe /C $Command
I have no idea why this exact Json works with Curl but not with Invoke-RestMethod
but since it works I'm not going to dig further.