dsQuery worked for getting a list of tags. REST API isn't working

I’m starting to update the code for this API Key sunsetting. (Kind of annoyed with this…)

I have OAuth working and I’m storing the tokens in a database and refreshing every hour roughly. That’s fine.

My app has 1016 tags but we can only request 1000 tags at a time so I have to make two requests to get the complete list.

In the past, I used dsQuery with offsets to request each subsequent set of tags.

With my OAuth login, it looks like it’s using the V1 REST API which doesn’t have dsQuery. It does have a tags() method and it looks like it’s supposed use limit and offset, but it doesn’t work. Here’s what I’m using…

$limit = 100;
$offset = null;

do {
  $params = [
            'limit' => $limit,
            'offset' => $offset
            ];

  $response = $infusionsoft->tags()->get($params);


  ...
}

It doesn’t matter what I set the limit to, it always returns 1000 tags.
The $offset doesn’t work either.

Any ideas of how to get this to work?

With this much trouble on just the first script I’m updating (of 35), I’m not looking forward to this.

I noticed this in the response:

GET /crm/rest/v1/tags?

I’m using OAuth but I thought that was using REST V2

Any help??

Hi @Tom_Nunamaker,

REST v1 - List Tags - Documentation: Keap REST API

What you need to do is to set “$offset = 0;” at the start. Then in your “do” loop you need to increment “$offset” by the “$limit” value. That will set the starting point to the next 100 records.

Try this code out below. The “while” statement added as well.

$limit = 100;
$offset = 0;

do {
  $params = [
            'limit' => $limit,
            'offset' => $offset
            ];

  $response = $infusionsoft->tags()->get($params);
   
  $offset += $limit; 

   .....etc.....
}
while($response || count($response) === $limit);

The Keap PHP SDK is stuck on REST v1, due to the ongoing development of REST v2. When Keap are comfortable that that v2 matches the functionality of v1 they will swap it over.

Hope that helps.

Thanks @Pav

I initialized the offset to 0 and I have been adding the $limit to it in each loop.

I’m still having issues:

  • The API always returns 1000 tags regardless of what my $limit is
  • The second API call returns the original 1000 tags and ignores the offset

Does this work for anyone else or is the REST V1 API broken?

Apologises, I do not use Keap SDK for several reasons. You need to apply the “where()” function.

$response = $infusionsoft->tags()->where($params)->get();