Skip to main content

Hi,

I am running a weekly process in MS .net to “unset” some custom properties. I first run a call using the code below to retrieve the PID to use in the unset call.   It fails to retrieve the PID in about 20% of the calls returning the error message “To Many Requests”.  The failures are not sequential and the volume is not high.  The last time it ran there were 45 calls to retrieve the PID and 9 of them failed with the “Too Many Requests” error message.  If I return the 9 (in this case) they are all successful.  Anyone know why this may be happening?  It runs at 2:30am EST every Monday.

John

s = "https://a.klaviyo.com/api/v2/people/search?api_key=pk_xxxxxxxxxxxxx&email=<EMAIL>";
                s = s.Replace("<EMAIL>", email);
                var client = new RestClient(s);
                var request = new RestRequest(Method.GET);
                request.AddHeader("Accept", "application/json");
                request.AddHeader("Content-Type", "application/json");
                var response = client.Execute(request);
                if (response.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    msg = "PID failed to retrieve for email " + email;
                    writelog("E", 0, response, msg);
                }
                else
                {
                   
                    DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(apiresponse));
                    MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(response.Content));
                    stream.Position = 0;
                    apiresponse responseDetail = (apiresponse)jsonSerializer.ReadObject(stream);
                    pid = responseDetail.id;
                    stream.Close();
                    {
                        msg = "PID, " + pid + " successfully retrieved for email " + email;
                        writelog("I", 0, null, msg);
                    }
                }

Hi @John99, welcome to the community!

I wonder if you are hitting throttle/rate limits - I realize the volume is Low but maybe they are happening too quickly?  When you said you received the error “Too Many Requests” - was that a 429 Error Code?  

See here for the error code table:

Joe


Hi Joe, 

Thanks for the quick response.  Yes, it is a 429 Error Code..  Should I add maybe a .5 second delay between calls?

 

John


Reply