Coder Social home page Coder Social logo

Comments (10)

psonnera avatar psonnera commented on July 20, 2024

I'm not sure this is covered by this documentation, did you ask in Discord? https://github.com/nightscout/cgm-remote-monitor/issues/new/choose

from nightscout.github.io.

bewest avatar bewest commented on July 20, 2024

Howdy @dcallagh. I think you would benefit from looking at curl and a tool like json to accomplish something like the following:

cat <<EOT | json | curl --data-binary @-  -H "Content-Type: application/json" -H "API_SECRET: $hashed_secret" https:///api/1/treatments.json
[{"eventType":"","created_at":"2021-04-10T15:28:00Z","carbs":27,"insulin":3.9}]"
EOT

Note that the api secret has been hashed using something like echo -n mylongplainsecret | sha1sum - | cut -d ' ' -f 1. Also, there are subtle differences between -d or --data and --data-binary: --data-binary without any extra urlencoding is probably what you want.

from nightscout.github.io.

dcallagh avatar dcallagh commented on July 20, 2024

Hi Ben,

      Thanks for the help, as I suspected the CURL on nightscout swagger is wrong.   I have had another look using the nightscout 'ADD treatment' panel, and the error is the name of the auth token: Lowercase "api-secret" is correct so the swagger page should be corrected. I had previously looked at the ADD panel but was focussed on the sha1 value and did not notice the api token was a different name. 

Result from using your suggested curl command slightly amended to include Json embedded, but still with the upper case API_SECRET gave the same error:
$ hashed_scret=echo -n <passkey> | sha1sum - | cut -d ' ' -f 1
$ curl --data-binary '[{"eventType":"","created_at":"2021-04-10T15:28:00Z","carbs":27,"insulin":3.9}]' -H "Content-Type: application/json" -H "API_SECRET: $hashed_scret" -X POST https://.herokuapp.com/api/v1/treatments.json

{"status":401,"message":"Unauthorized","description":"Invalid/Missing"}

from nightscout.github.io.

bolattleubayev avatar bolattleubayev commented on July 20, 2024

Hey @dcallagh ,

I think that I have found something for that matter. Here it says that you need to put API-SECRET instead of API_SECRET to the header and the secret itself should be SHA1 hashed

Hope that helps!

from nightscout.github.io.

tzachi-dar avatar tzachi-dar commented on July 20, 2024

I must say that this did not seem to work with latest version, but in any case if someone gets into here:
REST_ENDPOINT=https://snirdev.hopto.org/api/v1/entries.json?token=try-0da467168cf4xxxx
curl -m 30 -s -X POST --data-binary @${ENTRIES} -H "content-type: application/json" ${REST_ENDPOINT}

This works, with the new security model where the token has write permissions.

from nightscout.github.io.

dinizmauricio avatar dinizmauricio commented on July 20, 2024

@dcallagh,
Did you manage to resolve the problem? I'm going through the same situation.

from nightscout.github.io.

dcallagh avatar dcallagh commented on July 20, 2024

from nightscout.github.io.

dcallagh avatar dcallagh commented on July 20, 2024

from nightscout.github.io.

dinizmauricio avatar dinizmauricio commented on July 20, 2024

@dcallagh, I tried with the code below, but it's not working. :/

#############
myHash='d018020ba8f49a010afdbabf7e8be89441085750'
header1 = {'api-secret': myHash}
data = {
"carbs": 10
}
resposta = requests.post('http://192.168.0.1:17580/entries', headers=header1, json=data)

print(resposta.status_code)

print (resposta.text)

from nightscout.github.io.

dcallagh avatar dcallagh commented on July 20, 2024

from nightscout.github.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.