lukasroegner / homebridge-philips-hue-sync-box

Homebridge plugin for the Philips Hue Sync Box.
MIT License
55 stars 12 forks source link

IOS Shortcut POST JSON #45

Closed crazymaca69 closed 3 years ago

crazymaca69 commented 3 years ago

I'm struggling to build the JSON for the POST request within shortcuts using 'get contents of'

This is what I've got so far

Get contents of - http://"IP":"port"/state Method - POST Headers - Authorisation - "my token" Request Body - JSON

Then I add new field and select Text and then key - mode Text - music

It doesn't seem to work but I've never used shortcuts to build a JSON so maybe I'm missing something.

A GET request works fine by the way so I know my API Token etc are all good.

crazymaca69 commented 3 years ago

For anyone trying to implement the API using Shortcuts in IOS...

Open Shortcuts - Add Action - search for 'Text'

Paste the JSON script in here. For Sync Music you just need - {"mode":"music"}

Add Action - search for "Set Name" Overwrite "Name" with something like "Sync.JSON" Select "Show More" and enable "Don't include File Extension"

Add Action - Search for "Set Variable" Overwrite "Variable Name" with "SyncJSON" (Notice there is no Full stop)

Add Action - Search for "Get contents of URL" Shortcuts will try and put MusicJSON as the URL, delete this and type in: http://"IP of home bridge Server":40220/state Select "Show More" Under "Method" select "POST" Under "Headers" Select "Add New Header" For "Key" type "Authorization", and for "Text" type your API token you created on your homebridge server. (This can be anything you want, you just need to make sure it is defined in the homebridge config file) Under "Request Body" select "File" Under "File" Select "SyncJSON"

Hit play and test.

Duplicate the shortcut and change the text in the first step from music to either video/game/passthrough/powersave

Enjoy :)