Using curl to add ".qi" file - via authentication "method"

Hi, I’m using “curl” to add an inbound “file” to notehub.io - the notehub request follows the “Authentication” method as described in “using Notehub API/Authenticating”. Here’s the command – (in a Windows batch file). I use line extenders (^) to better view the command. I followed the “Programmatic API access” steps to create a “client id” and a “client secret key”.

curl -X POST -L “https://notehub.io/oauth2/token” -H “content-type:application/x-www-form-urlencoded” -d “grant_type=client_credentials” ^
-d “client_id=*************” -d “client_secret=**************” ^
-d “{"req":"note.add","file":"my-inbound.qi",{"command":"mycmd_6","id":"the_id6"}}”

The command returns what appears to be a “valid” a response. I shortened the “access_token” for readability …

{“access_token”:“zkXV2qR…KFZc”,“expires_in”:1799,“scope”:“”,“token_type”:“bearer”}

Upon completion, I expected an entry to be added in the Notehub/Events page (similar to Adding the note in the Devices page) – showing “my-inbound.qi” and data fields. Unfortunately, no entry is made.

Any idea of what I’m doing wrong? Do I need to create a route?

regards, Rich

Hey Rich,

You need to get the token and add the Note in two different requests.

Request #1: Getting a token

curl -X POST -L 'https://notehub.io/oauth2/token' -H 'content-type: application/x-www-form-urlencoded' -d grant_type=client_credentials -d client_id=*** -d client_secret=***

It looks like this one is working correctly for you because you’re getting back an access_token in the response, as expected.

Once you have the token you can use it to authenticate subsequent Notehub API requests.

Request #2: Adding a Note

curl -X POST -L 'https://api.notefile.net/v1/projects/app:bb37bf3b-969a-4f58-879c-b5b96fc34697/devices/dev:860322067705456/notes/test.qi' -H 'Authorization: Bearer ***' -d '{"body": {"temp": 72.22 }}'

You’ll want to change the AppUID and DeviceUID here to your own values. Then, replace the *** with the access_token you got back from the previous request.

If this works correctly you will see your event in your project’s Events page. If you have any questions let us know.

Thanks,
TJ