Getting Too Many API Requests error

Hi Guys,

I am trying to sync more than 2000 records from Keap to my local database. For this purpose, I am sending 1 API request per record. But Keap is giving T00 Many API requests error after 400 to 500 Calls.

I found a workaround to fix it by adding a 1 second delay before each call. By doind that, It worked perfectly. But now it is taking almost 30 minutes to sync these 2000 records.

Is there any better workaround for that?

Please let me know

Welcome @muhammad_Usman,

A few questions here.

It seems to me that you are using a Service Account Key or Personal Access Token for the API Connection?

What data are you querying from the Keap? You can get 1000 records in 1 query, but it seems that you are querying individual records for a particular reason.

What API Methods / Endpoints are you using?

Thanks

@Pav following is the code i am using.

$contact = $infusionsoft->contacts(‘xml’)->load($ifid,array(‘Email’,‘FirstName’,‘LastName’,‘Phone1’,‘Address2Street1’,‘Address2Street2’,‘Groups’,‘City2’,‘State2’,‘PostalCode2’,‘Birthday’,‘_ofmeals’,“_FoodCode0”,‘_PerminantPreferances’,‘_Bars’,
‘_Pancakes’,‘_PickUpLocation’,‘_AdditionalProteinBars’,‘_WeeklyPancakeOrder’,
‘_Changesthisweek’,‘_SpecialDeliveryInstructions’,‘_DeliveryRoute’,
‘_Meal1’,‘_Meal2’,‘_Meal3’,‘_Meal30’,‘_Meal5’,‘_Meal6’,‘_Meal7’,‘_Meal8’,
‘_CleanCheatz’,‘_CLEANCHEATZFROOTLOOPS’,‘_CLEANCHEATZREECESPIECES’,‘_CLEANCHEATZCOOKIES’,
‘_CLEANCHEATZCHOCOLATESPRINKLES’,‘_ProteinCookies’,‘_WeeklyWaffles’,‘_ClientResolution’,
‘_DeliveryDay’));

where $ifid is the userid stored in our database.

@muhammad_Usman, looking at the Keap SDK Contact Load function can only support one Contact Id.

What you need to do is to use the “DataService” - “query” function to be able to return multiple Contacts based on the Id numbers given.

The Example below will return the results for up to 1000 Contacts. The Contact Ids “1,2,3,4” have been provided as an Array of Integers. Note, you can only supply a maximum of 1000 Contact Ids at a given time.

By passing an Array, it is basically doing an equivalent SQL Select with an “IN” query. In other words, do a search on the Contacts where Id match the list provided.

$contacts = $infusionsoft->data()->query("Contact", 1000, 0, [ 'Id' => [ 1, 2, 3, 4] ], ["Id", "FirstName", "LastName"], "Id", true);

When you query your database, you need to collect the Contact Id numbers and pass them as an array as shown above. No need to run the API query for each individual contact, otherwise you will have the same issue again.

More information about the “DataService” - “query” function, see “queryData” - Point (7).

https://developer.keap.com/docs/xml-rpc/#data-query-a-data-table

Hope that was clear.