CURL API request denying session token

Hi,
I am trying to send variables to my notecard via curl commands from our website. I have successfully retrieved a session token by curl command. However when I try to push a note to the device, I keep receiving an error.

My CURL command (Windows CMD):
curl -L “https://api.notefile.net/req?product=[productUID]&device=[deviceUID]&project=[project]” --header “X_SESSION_TOKEN: [token]” --data “{“req”:“note.add”, “body”:{“test”:“true”}}”

Response:
{“err”:“please sign-in and then provide an authentication token to process this request”}

I have tried logging in multiple times and adjusting quotations. What am I doing wrong?

Hey @NathanJC,

Hello and welcome to the Blues community :slightly_smiling_face:

I hate trying to get the quotes right on these commands lol. I spotted two things that might be off with what you have:

  • The header should be X-SESSION-TOKEN and not X_SESSION_TOKEN.
  • Use single quotes around the value of your --data option. So --data '{"req":"note.add", "body":{"test":"true"}}'

Give those two changes a shot and hopefully everything will go through ok.

Actually for Windows you’ll likely need double quotes around your --data option, and to escape the quotes within. So:

--data "{\"req\":\"note.add\", \"body\":{\"test\":\"true\"}}"

Hi mate,
Thanks for your help. I hadn’t seen the issue with token syntax. My updated call now looks like this:

curl -L “https://api.notefile.req?product=[productUID]&device=[deviceUID]&project=[projectUID]” --header “X-SESSION-TOKEN: [token]” --data “{\“req\”:\“note.add\”, \“body\”:{\“test\”:\“true\”}}”

It appears to be happy with the session token now, but it is returning another error:
“curl: (6) Could not resolve host: api.notefile.req”

Hi @NathanJC!

Editing these long command lines can be a chore! It looks like a small change crept in with the latest edits, changing the hostname from api.notefile.net to api.notefile.req.

Try this

curl -L “https://api.notefile.net/req?product=[productUID]&device=[deviceUID]&project=[projectUID]” --header “X-SESSION-TOKEN: [token]” --data “{\“req\”:\“note.add\”, \“body\”:{\“test\”:\“true\”}}”

The changed part comes before?product. Everything after that remains the same.

With that fixed, you should be all set.

3 Likes

Thank you for spotting that. It is working properly now.

2 Likes