# API fun with jq

**URL:** <https://forum.beeminder.com/t/api-fun-with-jq/10325>\
**Category:** Tech\
**Created:** [May 4, 2022, 2:26pm UTC](https://forum.beeminder.com/t/api-fun-with-jq/10325 "2022-05-04T14:26:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ianminds](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.beeminder.com/ianminds/32/4188_2.png) [@ianminds](https://forum.beeminder.com/u/ianminds)\
**Post date:** [May 4, 2022, 2:26pm UTC](https://forum.beeminder.com/t/api-fun-with-jq/10325/1 "2022-05-04T14:26:05Z")

</div>

I needed a way to subtract an offset from all data points on goal.

I ended up with the following one-liner, which might be useful to other people. Basically it’s a generalized version of the scale datapoints feature, except that it doesn’t touch the road at all. That might be a fun extension…

```auto
username=...
auth_token=...
goal=test
api=https://www.beeminder.com/api/v1/
curl -s -X GET $api/users/$username/goals/$goal/datapoints.json?auth_token=$auth_token | jq -c '.[] | {value: (.value + .999), id}' | while read -r json; do id=$(jq -r '.id' < <(echo $json)); curl -s -X PUT $api/users/$username/goals/$goal/datapoints/$id.json?auth_token=$auth_token --header "Content-Type: application/json" -d $json &>/dev/null; sleep 0.5; done

```

And here’s sort of a [repost](https://forum.beeminder.com/t/urgency-load-metric/5648/29) calculating a parametrised version of the urgency\_load metric:

```auto
param=7; curl -s -X GET https://www.beeminder.com/api/v1/users/$username/goals.json?auth_token=$auth_token | jq '[.[] | select(.won | not) | select(.safebuf < '$param') | '$param' - .safebuf ] | add'

```
