Help adding a datapoint from Tasker using Beeminder API


#1

Hi guys, I could really use some help grokking the API - more specifically how to http POST to the datapoints endpoint to add a datapoint - I’ve lost four hours to this and I’m pulling my hair out.

I’m trying to do this from Tasker, and I originally set up an AutoWeb API configuration to do so, but when I remembered that Tasker has a built in http-post action that will suffice, as I’m not doing anything too complex, so Autoweb was probably overkill.

Looking at the AutoWeb logs, I’m fairly certain that what it is sending is equivalent to curl -X POST https://www.beeminder.com/api/v1/users/me/goals/test/datapoints.json?auth_token=XXXX -d value=1.
But the result I get is simply all the datapoints for this goal (without the new point I’m trying to add), as though I had called it using GET instead, and it does not add any new datapoints to he goal. There is no error message - the API responds with the datapoints for the goal, with no complaints.

I get the same thing trying it with the Tasker http-post action.

Weirdly, when I try to test it directly using curl on windows I got a “301 Moved Permanently” Error, which I’m almost certain is a red herring and due to some part of my local curl config being borked. But it made it very hard to test the correct construction!

Edit: I just figured this out - I was missing the www. This fixed posting via CURL, but I still cant get it to work via tasker, even after adding the www. It’s als weired that through tasker it returned the datapoints even without the www, and not a 301 error

When doing a POST to datapoints.json, does anyone know what parts should be parameters, what are headers, and what is in the body, and also what format the body takes?

Or better yet, does anyone out there use Autoweb and want to take a look at my API config? I have added it to AutoWeb’s shared directory.


#2

OK, I have managed to get it to add a datapoint via Autoweb after adding in the www to the address, and by submitting the value parameter as a “Query” type input in autoweb- ie url encoded. But it only seems to use one of the variables this way - my comment input was ignored.

Posting with a message body of eg value=1&comment=test causes it to flame out with some new and different error.


#3

I’ve used the API a lot from both curl and Python, and it basically works the way it says it does.

When you do something like:

curl -X POST https://www.beeminder.com/api/v1/users/alice/goals/weight/datapoints.json
-d auth_token=abc123
-d timestamp=1325523600
-d value=130.1
-d comment=sweat+a+lot+today

per the docs, you’re using curl’s -d, which basically sends it like a webbrowser does.

  -d, --data <data>

         (HTTP) Sends the specified data in  a  POST  request  to  the  HTTP

         server,  in the same way that a browser does when a user has filled

         in an HTML form and presses the submit button. This will cause curl

         to  pass  the  data  to  the server using the content-type applica-

         tion/x-www-form-urlencoded.  Compare to -F, --form.

Lemme do one with curl and get all the headers for you:

$ curl -v -X POST https://www.beeminder.com/api/v1/users/adamwolf/goals/coffeeless_days/datapoints.json -d auth_token=REDACTED -d value=1 -d comment=helloworld

Note: Unnecessary use of -X or --request, POST is already inferred.

  • Trying 23.92.16.25…

  • TCP_NODELAY set

  • Connected to www.beeminder.com (23.92.16.25) port 443 (#0)

  • ALPN, offering h2

  • ALPN, offering http/1.1

  • Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH

  • successfully set certificate verify locations:

  • CAfile: /etc/ssl/cert.pem

CApath: none

  • TLSv1.2 (OUT), TLS handshake, Client hello (1):

  • TLSv1.2 (IN), TLS handshake, Server hello (2):

  • TLSv1.2 (IN), TLS handshake, Certificate (11):

  • TLSv1.2 (IN), TLS handshake, Server key exchange (12):

  • TLSv1.2 (IN), TLS handshake, Server finished (14):

  • TLSv1.2 (OUT), TLS handshake, Client key exchange (16):

  • TLSv1.2 (OUT), TLS change cipher, Client hello (1):

  • TLSv1.2 (OUT), TLS handshake, Finished (20):

  • TLSv1.2 (IN), TLS change cipher, Client hello (1):

  • TLSv1.2 (IN), TLS handshake, Finished (20):

  • SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384

  • ALPN, server accepted to use http/1.1

  • Server certificate:

  • subject: OU=Domain Control Validated; CN=*.beeminder.com

  • start date: Sep 15 01:00:49 2015 GMT

  • expire date: Sep 15 01:00:49 2018 GMT

  • subjectAltName: host “www.beeminder.com” matched cert’s “*.beeminder.com”

  • issuer: C=BE; O=GlobalSign nv-sa; CN=AlphaSSL CA - SHA256 - G2

  • SSL certificate verify ok.

> POST /api/v1/users/adamwolf/goals/coffeeless_days/datapoints.json HTTP/1.1

> Host: www.beeminder.com

> User-Agent: curl/7.54.0

> Accept: /

> Content-Length: 58

> Content-Type: application/x-www-form-urlencoded

>

  • upload completely sent off: 58 out of 58 bytes

< HTTP/1.1 200 OK

< Content-Type: application/json; charset=utf-8

< Transfer-Encoding: chunked

< Connection: keep-alive

< Status: 200 OK

< Cache-Control: max-age=0, private, must-revalidate

< X-XSS-Protection: 1; mode=block

< X-Request-Id: 7b49bcb9-0d80-45d9-be78-50e5acf5563e

< X-UA-Compatible: chrome=1

< ETag: “415d47182e8c853ae81f4d45f04a76d7”

< X-Frame-Options: SAMEORIGIN

< X-Runtime: 0.213489

< X-Content-Type-Options: nosniff

< Date: Wed, 08 Aug 2018 13:37:04 GMT

< Set-Cookie: _beeminder_session=REDACTED; path=/; HttpOnly

< X-Powered-By: Phusion Passenger Enterprise 5.1.10

< Server: nginx/1.12.1 + Phusion Passenger 5.1.10

<

{“timestamp”:1533735424,“value”:1.0,“comment”:“helloworld”,“id”:“5b6af200bfec0316940003e7”,“updated_at”:1533735424,“requestid”:null,“canonical”:“08 1 “helloworld””,“fulltext”:“2018-Aug-08 entered at 08:37 via api”,“origin”:“api”,“daystamp”:“20180808”,“status”:“created”}%

I think that without another user who has already done this, your best bet may be to email support. They miiight be able to take a look at your API calls. Maybe it’s something silly like Autoweb is sending GETs instead?

Please let us know if you figure it out!

On Wed, Aug 8, 2018 at 8:06 AM imoatama <beeminder@discoursemail.com> wrote:

imoatama
August 8

OK, I have managed to get it to add a datapoint via Autoweb after adding in the www to the address, and by submitting the value parameter as a “Query” type input in autoweb- ie url encoded. But it only seems to use one of the variables this way - my comment input was ignored.

Posting with a message body of eg value=1&comment=test causes it to flame out with some new and different error.

Visit Topic or reply to this email to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, click here.


My list of bugs and feature requests
#4

I would like help with this as well, specifically how to add a datapoint that’s a variable. See bugs 3 and 16 on my list: My list of bugs and feature requests