Is it possible to download datapoints since specified time for a single goal through the API?

I can download all datapoints for a goal, or datapoints dince some time for all goals. But what about marrying these two options?

1 Like

Yes, indirectly, but it’s a hack because the datapoints endpoint doesn’t appear to support either diff_since or datapoints_count.

Workaround is to fetch the goal object with the datapoint constraints, and then return the datapoints instead of the goal…

Here, have some perl from my beemapi.pl:

# bizarre implementation because datapoints.json doesn't respect diff_since
sub beemfetchsince {
  my ( $u, $g, $t ) = @_;

  my $ua = LWP::UserAgent->new;
  my $uri = $beembase .
        "users/$u/goals/$g.json?auth_token=$beemauth&diff_since=$t&datapoints=true";

  my $resp = $ua->get($uri);
  beemerr('GET', $uri, {}, $resp);
  my $results = decode_json($resp->content);

  return $results->{datapoints};
}
1 Like

Thanks, it worked! See https://github.com/mbork/beeminder.el/commit/d5a0ec82c879ed70d38825f8ce62bc3f93ba8821

3 Likes