0

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}}:

IFTTT Webhooks setup

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}}:

IFTTT actual notification

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:

IFTTT Logs

Tanaka Saito
  • 943
  • 1
  • 17
  • 40
  • The second approach looks correct, you probably just need to change `-Method Get` to `-Method Post` – Mathias R. Jessen Sep 29 '22 at 08:50
  • I thought so too, but the documentation says that you can use both GET and POST. Changing to POST throws the error Invoke-RestMethod: {"errors":[{"message":"Unexpected token v in JSON at position 0"}]} if I use -Body. If I do a ConvertTo-Json with -Body, or if I use the direct ?value=TESTVALUE in the URL it still sends the literal string {{value1}}. – Tanaka Saito Sep 29 '22 at 09:32
  • My guess is that the documentation says that because you can use `GET` _when you don't need to pass additional parameters_. Please try all 3 at once: convert the body to json, pass the resulting json string to `-Body`, and use Post: `Invoke-RestMethod -Method Post -Uri $WebhookURL -Body ($Body |ConvertTo-Json -Compress) -ContentType "application/json"` – Mathias R. Jessen Sep 29 '22 at 09:35
  • Do you not need to replace the whole ```{event}``` in the uri template, rather than just the ```event``` part? You've got ```https://maker.ifttt.com/trigger/{MyEvent}/json/with/key/{MyKey}```, but my guess would be ```https://maker.ifttt.com/trigger/MyEvent/json/with/key/MyKey``` instead. – mclayton Sep 29 '22 at 09:36
  • @MathiasR.Jessen I did all those but still get the {{value1}}. I also tried to add value2 = "" and value3 = "" to see if that was the problem but the same result :( I also tried with and without -Compress but no effect. – Tanaka Saito Sep 29 '22 at 09:38
  • @mclayton I'm using those as placeholders because I don't want to publicly post my Key. I'm using the actual values for my event and my key, and the notification goes through correctly so that's not the problem, it's the value that is not being passed along. – Tanaka Saito Sep 29 '22 at 09:38
  • @TanakaSaito - sure, but are you including the curly brackets in your real code? i.e. are you using ```{MyKey}``` or ```MyKey``` in the uri? – mclayton Sep 29 '22 at 09:40
  • @mclayton I'm using MyKey without the curly brackets. – Tanaka Saito Sep 29 '22 at 09:42
  • I'm not sure if it's the answer to the question but I found a workaround: run it with curl instead. Unfortunately it took me some time to realise that all the examples in IFTTT don't work because they use single quotation mark and either curl, Powershell, CMD, or whatever it is doesn't like that. Changing to double quotation marks and running everything in curl solved it. I have absolutely no idea why the Invoke-RestMethod doesn't work with the exact same JSON though. – Tanaka Saito Sep 29 '22 at 13:55

1 Answers1

0

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.

Tanaka Saito
  • 943
  • 1
  • 17
  • 40