Skip to main content
Solved

API PID Request "Too Many Requests" Error


Forum|alt.badge.img+2

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);
                    }
                }

Best answer by retention

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

View original
Did this topic or the replies in the thread help you find an answer to your question?

2 replies

retention
Partner - Platinum
Forum|alt.badge.img+62
  • 2025 Champion
  • 944 replies
  • Answer
  • June 15, 2022

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


Forum|alt.badge.img+2
  • Author
  • Contributor I
  • 2 replies
  • June 15, 2022

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