Skip to main content
Contributor I
June 15, 2022
Solved

API PID Request "Too Many Requests" Error

  • June 15, 2022
  • 2 replies
  • 366 views

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

    This topic has been closed for replies.
    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

    2 replies

    retention
    Partner - Platinum
    retentionAnswer
    2025 Champion
    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

    Joseph Hsieh // retentioncommerce.com // X: @retention
    John99Author
    Contributor I
    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