2blane / OctoPrint-Webhooks

Make OctoPrint events call your custom webhooks!
GNU Affero General Public License v3.0
28 stars 19 forks source link

Invalid API Response: Cannot POST /use/xxxxxxxxxxx #10

Closed terryb58 closed 4 years ago

terryb58 commented 4 years ago

I'm trying to setup the plugin but when I test I get a message saying "Invalid API Response: Cannot POST /use/xxxxxxxxxxx".

The url I've set is https://maker.ifttt.com/use/xxxxxxxxx I've copied my octoprint instance API secret into the API secret setting and I've set my device identifier. HTTP Method is POST and for content type I've tried both JSON and urlencoded.

I have the applet setup on IFTTT. It should send me an email as a result of the test event. What am I missing?

2blane commented 4 years ago

@terryb58 Do you have the documentation of what you are trying to connect it to? Just clicking on the url you are sending it to looks like it should be formatted as https://maker.ifttt.com/trigger/{event}/with/key/xxxxxxxxx instead of /use/xxxxxx but without the docs I can't be sure.

terryb58 commented 4 years ago

Hi Blane! Good to hear from you. I've been trying to fix this all day. I finally found something helpful and it turns out to be exactly what you said. I need to be calling is in the form: https://maker.ifttt.com/trigger/EVENT/with/key/xxxxxxxxxxxx

I don't know why they did that but they embedded the event in the URL instead of putting it after everything else. Problem now is, how do I put a variable where event should be. I tried @event but that didn't work. Is there a way? After reading your message I also tried {event} it succeeded but no substitution occurred.

Btw, I've been having trouble testing because when I edit the URL in the Webhook Settings section the URL above doesn't update. I've had to delete the entire thing, create a new hook, reenter the API secret, and try a new URL.

2blane commented 4 years ago

@terryb58 glad to hear it!

So, as far as the settings go, it's a little funky how OctoPrint works but anytime the settings are updated you'll get this alert box that pops up and says Settings Change detected like the following image:

Screen Shot 2020-05-25 at 3 58 01 PM

Instead of selecting an option, click outside the alert box entirely and it should go away. If you are still running into issues then refreshing the page sometimes help.

As far as the url goes, it doesn't allow substitution just yet so '@topic' (@event is called @topic) won't do anything yet. I can work on that right now though give me a few minutes. Instead, you can change the Advanced - Data parameter to something like the following to pass in the name of the event, a description, and an id for your printer: { "value1":"@deviceIdentifier", "value2":"@message", "value3":"@topic" }

2blane commented 4 years ago

@terryb58 Another option is to create a webhook for each event type and they would call a different url. So webhook 1 would only have Print Start enabled - and it would call the url /Start/with/key/xxx . Webhook 2 would only have Print Done enabled - and it would call the url /Done/with/key/xxx .

But, I'm working on the url replacement right now so should be done within the hour

2blane commented 4 years ago

@terryb58 Just released 3.0.3 that allows you to add replacement params inside the url. So now, you can do: https://maker.ifttt.com/trigger/@topic/with/key/xxxxxxxxxxxx You could also set a custom message for each topic/event. Under the EVENTS section, toggle on the events you want triggered, then set the text in the text boxes. This will set the @message parameter for that particular event. For instance, if you enable the 'Print Done' event, then you set the text box under 'Print Done' to be 'Completed' -> whenever the 'Print Done' event is called, the @message parameter will be set to 'Completed'. So then, you can do something like the following allowing you to provide a custom name for each event. https://maker.ifttt.com/trigger/@message/with/key/xxxxxxxxxxxx

terryb58 commented 4 years ago

It works! That was quick! I was actually working on the first options you provided not knowing that you'd released an update that allowed substitution. Thank you Blane!

As for the settings, that alert box popped up once while I was still starting to fiddle with the plugin. I hadn't read your warning so I clicked "Reload only non-conflicting changes". Through all my changes and restarts It hasn't popped up since. But if it ever does I'll know what to do. Thanks.