Spark.publish - errors


I created a “spark.publish event” in my code. When trying to run:

curl -H “Authorization: Bearer {my-access-token}”

I get an error message:

“code”: 400,
“error”: “invalid_grant”,
“error_description”: “The access token provided is invalid.”

I used the access token on the “Settings” page with my curl statement.

Anyone ay idea what goes wrong here?


I’ve personally got a couple of files in which my acces tokens are stored. Could it be that you’ve taken yours out of a similar one, while the “live” one has expired in the mean time? Or did you really take it directly out of the IDE?

I took the one in the IDE; and since this one didn’t work i tried by resetting the token. So yes the token comes from the IDE.


@gdillen I’m not sure what’s wrong. I can run

curl -H "Authorization: Bearer {my-access-token}"

Which works when a core publishes the brett-test event.

I’ve been trying to recreate your error. If I switch one of the letters in my access token from lower case to upper case, then I get the exact error message. Maybe that’s your problem?

UPDATE: I tried my access token with all upper case letters, and I get the invalid_grant error. All lower case works.

@brett13: thanks… but all my tokens are in lowercase.

@gdillen Got me stumped then. I’ll pull in the Spark guys @Dave @jgoggins

Why don’t you try the other URL syntax and see if that works for you:<<access token hex number here>>

This is the public stream of events, so there should be a lot of them for you to see for testing.

@bko this seems to work. i get an “:ok”; at least it doesn’t give the invalid grant & invalid access token errors.

Hey Gang,

Hmm, no reason why the bearer token shouldn’t work, but it’s possible curl was not sending a GET request, so it might help to specify that method with a -X GET or something. :smile:



Hey @bko, great suggestion, the URL you shared is not the public stream though, subtle mistake, no need for the “/devices” in there. I thought you had it right too, but then tried it myself, and looked closer at the docs Both the following requests do the same thing:

curl -H "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"


curl ''

@jgoggins the public events curl work.

Here’s my code I commented out (and don’t publish all the code) and left only the Spark.publish event statement.

void setup() {


void loop() {

 Spark.publish("my-event", "TEST", 60, PRIVATE);


UPDATE: obviously the { and } are not part of the statement in the curl; as @jgoggins mentions
curl -H “Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”
works; it displays “:ok”, but not “TEST” during the execution of every loop.

My bad! Cut and paste error from some working code.

Thanks for the correction.

You know that event publishing is rate-limited, right? You will be limited to one per second on average with a burst of up to four events allowed. Have you factored that into your sketch somehow?

@bko yes i did. I only publish when an interrupt event (so in an interrupt handler) happens. The code I showed was only to solve the problem with the access token.

UPDATE: working fine now.

Thanks to all.

1 Like

Rad! Glad you are up and running @gdillen ! :smile: