Call on a curl command with a function [Photon]

First of all im quite new with particle photon, so this maybe a stupid question.

Im making an alarmclock that will open up the blinds of my bedroom and also hit play on spotify when the alarm starts.

What im having a problem understanding is how i can make a function that will hit this play button towards spotifys API when the alarm turns on. I have a curl command that works, but how can i get the photon to send this?
Or is it easier to make an webhook? i have tried making a webhook also, but i dont understand how i can call on this with a function, how i add the token and so on. Printscreens would help alot with webhooks if your using the particle website to make it.

my curl command to get spotify playing:

curl -k -X "PUT" "https://api.spotify.com/v1/me/player/play" 
-H "Accept: application/json" 
-H "Content-Type: application/json" 
-H "Authorization: Bearer BQDkUL7jGRcQn9zJnWxatXzjGlKyXdKw58LLw6cPMtENPjdSzZgELvGkJesgmzefl3tgsJ-Fmh4fNUXD8DFxXYvYTat_4wCc0ZRlRDQMS9-_XwjEeFnYwWhNqfvRPkUJS8rjDtdBj9PiBDg"

HTTPS requests are not easily sent from the Photon directly.
You could try the contributed HTTPSClient-Particle library or go with webhooks.

To trigger a webhook you just need to call Particle.publish() with the respective event name for that webhook.

1 Like

How do i make a webhook that will trigger the spotify playbutton?

Have you had a look at the docs and the integrations page on Particle Console?
This should be quite self explanatory, but if you have problems finding your way round, posting a specific question where you got stuck or what isn’t clear will get you your answer quicker :wink:

Im not sure where i should put what.


Hmm, I think your target url would best fit … hmm … into here, or not?

I guess this would be a good candidate to change from POST to … uhm PUT?

Judging by your content-type one of the other options provided here may possibly fit better?

Selecting the correct content-type will reveal other obvious answers.

The only “tricky” bit might be how to provide the “Authorization: Bearer …”, but that’s not too difficult once you got the other fields set correctly. A few keywords in that respect will be Particle.publish(), the data parameter thereof and {{PARTICLE_EVEN_VALUE}} which can be used to inject that into webhook value fields.

BTW, the info bullet next to each field caption (e.g. image) can be hovered to reveal some extra info too.

That should at least get you set up for the original curl command you tried to have the Photon execute.
For adding the request body of your later post, things may get a bit more involved, but not too complicated either. Keyword: JSON Data - Custom

i reckon i need to put the token i get from spotify somewhere. Should i translate the curl command into json? and should i remove the few lines of json that is there as standar?

More along this line


The {{{PARTICLE_EVENT_VALUE}}} is what you’ll get from your Particle.publish() as payload (data) parameter and you can use {{PARTICLE_EVENT_VALUE}} as placeholder in the webhook “payload” - in this case as part of the header "Authorization" : "Bearer ...." key/value pair.

Thank you so much for the help! i just put the authorization like this in the custom json setting and then it worked. Maybe not the best solution if i need to regenerate a new token evry hour.

json:

{
“Authorization”: “Bearer BQAAuIABobOnSDxGuKUGMg_vqL9eODvHYSJh6-4kFx0avGHyIj3x5TyVYX20pPJJelNs9dztyxxJupAR7PlDZT2-rUS5lJ9W_gFtVIwCjjFEXK9uWBwrODYDdXCqwUM_U6aQHb4MAByFk0I”
}