1

First of all I am not asking for API-specific help before anyone implies that. I am having a strange issue while consulting Active Campaign's API.

There's a specific endpoint I am using that is the GET contacts endpoint. Normally I don't have any issues with this endpoint, but in a specific case scenario where I use the segmentid get parameter I am having inconsistencies with the information.

I am using two ways to get to the API. One of them is Postman and the other one is my code using the Guzzle http client for php.

When I consult in Postman, on the first result I get this strange variable that says waiting => true and my contacts array is empty. When I consult the exact same endpoint again, the variable waiting is gone and I get the corresponding contacts array filled with the corresponding results. So, basically the idea is that if I do it a second time I get a result.

Now, on the other hand, with my code I am doing the exact same endpoint request and I tried repeating the request twice and both times I get the exact same result with waiting => true. I even tried the following:

foreach($segments as $index => $segment) {
    $segments[$index]['contacts'] = $this->ac->get_contacts(array(), $segment['id'], 'desc', 1, 30, 0);

    while($segments[$index]['contacts']->meta->waiting == true) {
        usleep(250000);
        $segments[$index]['contacts'] = $this->ac->get_contacts(array(), $segment['id'], 'desc', 1, 30, 0);
    }
}

But even like this it stays requesting forever and the result never changes and I end up getting a 504 error.

Now my main question is: How is it possible that the result of the same endpoint varies between those two ways of getting the information, and am I missing some parameter or what do I need in order to replicate the same behavior as Postman in order to obtain the information?

The Api-Token is the same, the endpoint is the same.

Mihail Minkov
  • 2,463
  • 2
  • 24
  • 41
  • I'm just guessing here, but from the documentation there's a section about rate-limiting. It only allows 5 requests per second and you might be consistently overstepping this boundary. Nowhere in the documentation it states what happens when you are rate-limited, but that might be what's happening here. Could you try waiting for 5 seconds instead of 250ms? I would also contact them and tell them to add that response to the documentation and how you should react to it. – JensV Apr 15 '19 at 12:21
  • Nope, in this case I do only 3 requests as in my test scenario I have 3 applicable segments. I have previously made requests that do a lot more in a second and even if they do get a little throttled, they execute pretty fast. I tried the 5 second waiting, made no difference, I even tried making the function recursive, no difference. I tried the same thing on Postman, I sent the first request and when it appeared with a waiting parameter I waited no more than a second and clicked again and immediately got the correct result. – Mihail Minkov Apr 15 '19 at 12:33
  • You're not using any caching on the guzzle client by chance? I don't really have an idea on what could cause the difference between the two – JensV Apr 15 '19 at 13:14
  • I am not sure how to check that info, but for example Postman has `Cache-Control →no-store, no-cache, must-revalidate, post-check=0, pre-check=0`, `Pragma →no-cache` and `Connection →keep-alive`. – Mihail Minkov Apr 15 '19 at 13:59
  • For guzzle, you'd have to write code according to [this](https://guzzle3.readthedocs.io/plugins/cache-plugin.html) but I'm guessing no then. You might be able to copy the headers of Postman into your guzzle client and check that. Other than that I'm out of ideas. – JensV Apr 15 '19 at 14:17

0 Answers0