Help requested: Creating a goal from the command line using the API

If anyone has a script they’re running from the command line (alternatively, PHP could work too) to create goals, I’d love to snag that from you to use myself. I’m not a programmer and my usual copy/pasting-until-something-runs method has not yielded any quick successes in terms of figuring out how to create goals from the API, and that’ something that would be really helpful for me. If anyone has a script to share, I’d really appreciate it!

(PSA: Don’t trust scripts other people write unless you know them or someone can vouch for them… or you’re feeling really, really lazy…)

5 Likes

Sure!

2 quick notes:

  1. This requires the program curl, but it comes with macOS and lots of Linuxes.

  2. This would leave your API key (which is sorta like a password) in your history file on your computer. If you have a reason to not be OK with this, then, uh, remove it, I guess, or don’t do this? Maybe your computer is shared with mischevious people who try to peek into your stuff, or you are always streaming to the public and they’ll see your API key as you type this and then go and mark all your goals as done and you’ll lose out on being as awesome as you could be? :slight_smile:

OK, all that being said:

  1. Get your API key. Go to https://www.beeminder.com/api/v1/auth_token.json, and there’s a part in quotes at the end (not username, not your username, and not auth_token). That’s like a password. Don’t share it with folks.

  2. Open a terminal, and (after tweaking for your circumstances), paste in the following, and then hit enter.

  curl -X POST https://www.beeminder.com/api/v1/users/me/goals.json \
    -d auth_token=AUTHTOKENGOESHERE \
    -d slug=exercise \
    -d title=Work+Out+More \
    -d goal_type=hustler \
    -d goaldate=1400000000 \
    -d gunits=workouts \
    -d rate=5 \
    -d goalval=null

You can edit or tweak basically all of those, after auth_token. See Beeminder API Reference for details on each one. hustler, for instance, is “Do More”. goaldate is in “epoch seconds”, or seconds since January 1 1970*. https://www.epochconverter.com/ can help you out.

“Exactly two out of three of goaldate , goalval , and rate are required”. I’m not sure if you can leave out the missing one or if you have to explicitly set it to null, but the example has the goalval set to null.

If you’d like, I can play around with Shortcuts and see what that looks like for something like this. Let me know!

Depending on what you’re doing, it may make sense to make the goal roughly correct, and then tweak it on the website.

8 Likes

Thanks Adam!!! I’m going to give this a try!

1 Like

That worked perfectly. Thanks! This is really all the tweaking I think it needs to be very, very useful for my use case.
Thanks!

2 Likes

I made this out of what @adamwolf helped with with, above. It’s a spreadsheet that will take the parameters that you enter or edit and spit out a goal creation script, a follow up script to tweak some of the settings for your initial set-up, and a script to update different things later.
It’s quick, imperfect, and just a jumping off point, but if it’s useful to you, grab a copy and play with it!

I’m going to be keeping a list of all of my goals in mine and when I want to clone a goal, I can duplicate the row, change what needs changing, and then just pop Terminal open and… done.

(PS - I tried to use examples that would make it obvious what kind of goal each was and used some random settings you’ll want to tweak.)

3 Likes

PS - There’s no character escaping so you’ll want to either stick to characters that don’t need to be escaped or fix up the formulas in your copy.

1 Like

OOPS! I had to create a new link cause there was an error with the first one. Changing it in the original post above but also re-posting it here, for those who interact with the forums via email.

3 Likes

That spreadsheet is glorious! Such a clever and useful idea - thank you!

2 Likes

Aw thanks @alys. I’ve been recreating goals like a mad person since I created it (mostly new versions of a lot of my old goals). (We’ll see how that works out!) I’ve also got some additional pieces to it in my own version that allow me to update my autodialer with just a copy/paste, so my goals are kind of all set-it-and-forget-it now. (I wish I were a little more proficient at coding so that I could write something sensible that I could share with others who might want something similar.)

2 Likes

Just found this - terrifically useful! Idea for the otherwise-tricky task of creating short-term goals for Beeminder (like, “do this thing for the next ten days”, or whatever). I love it, @mary !

2 Likes