<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Errors when enrolling many objects into a custom code workflow step in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/655077#M54375</link>
    <description>&lt;P&gt;Hey Wayde - did you ever find a solution for this? I have a similar challenge right now. Thanks, Phil&lt;/P&gt;</description>
    <pubDate>Fri, 24 Jun 2022 14:21:53 GMT</pubDate>
    <dc:creator>PBaxter</dc:creator>
    <dc:date>2022-06-24T14:21:53Z</dc:date>
    <item>
      <title>Errors when enrolling many objects into a custom code workflow step</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/566711#M50526</link>
      <description>&lt;P&gt;Hi folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a deal-based workflow which includes a custom code step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The custom code searches for a custom object id, then copies a property from the custom object to the deal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We get hundreds of new deals which are synced twice per day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When many deals are enrolled in the workflow at once, I'm seeing the custom code step return HTTP 400 errors, and only a small percentage of the enrolled deals actually complete the code step successfully.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I manually enrol any of the deals which failed individually, the code step completes successfully.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm thinking this is likely due to Search API limits, but the error reporting isn't helping me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-02-01 134409.png" style="width: 947px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/58452iEA9C3ECC996D95E9/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2022-02-01 134409.png" alt="Screenshot 2022-02-01 134409.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried adding a delay step before and after the custom code, but no cigar.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm thinking I may need to add a delay in the actual code step itself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions here?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 03:08:10 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/566711#M50526</guid>
      <dc:creator>WaydeChristie1</dc:creator>
      <dc:date>2022-02-01T03:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: Errors when enrolling many objects into a custom code workflow step</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/566811#M50530</link>
      <description>&lt;P&gt;I think my problem here is that many deals are enrolling at the same time, and there's no way for me to sequentially process them several seconds apart to avoid hitting the 4 per second search API limit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I add a delay step, or add a pause in my code step, the workflow still tries to process many search requests at the same time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I need is a way to process each deal in the workflow several seconds apart.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would I go about that?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 08:20:12 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/566811#M50530</guid>
      <dc:creator>WaydeChristie1</dc:creator>
      <dc:date>2022-02-01T08:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: Errors when enrolling many objects into a custom code workflow step</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/569232#M50625</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/124628"&gt;@WaydeChristie1&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN data-sheets-value="{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:&amp;quot;Why you don't trigger you workflow directly when a new deal is created so that at one instace it will run only for that one particular deal&amp;quot;}" data-sheets-userformat="{&amp;quot;2&amp;quot;:829,&amp;quot;3&amp;quot;:{&amp;quot;1&amp;quot;:0},&amp;quot;5&amp;quot;:{&amp;quot;1&amp;quot;:[{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:0,&amp;quot;5&amp;quot;:{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:0}},{&amp;quot;1&amp;quot;:0,&amp;quot;2&amp;quot;:0,&amp;quot;3&amp;quot;:3},{&amp;quot;1&amp;quot;:1,&amp;quot;2&amp;quot;:0,&amp;quot;4&amp;quot;:1}]},&amp;quot;6&amp;quot;:{&amp;quot;1&amp;quot;:[{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:0,&amp;quot;5&amp;quot;:{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:0}},{&amp;quot;1&amp;quot;:0,&amp;quot;2&amp;quot;:0,&amp;quot;3&amp;quot;:3},{&amp;quot;1&amp;quot;:1,&amp;quot;2&amp;quot;:0,&amp;quot;4&amp;quot;:1}]},&amp;quot;7&amp;quot;:{&amp;quot;1&amp;quot;:[{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:0,&amp;quot;5&amp;quot;:{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:0}},{&amp;quot;1&amp;quot;:0,&amp;quot;2&amp;quot;:0,&amp;quot;3&amp;quot;:3},{&amp;quot;1&amp;quot;:1,&amp;quot;2&amp;quot;:0,&amp;quot;4&amp;quot;:1}]},&amp;quot;8&amp;quot;:{&amp;quot;1&amp;quot;:[{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:0,&amp;quot;5&amp;quot;:{&amp;quot;1&amp;quot;:2,&amp;quot;2&amp;quot;:0}},{&amp;quot;1&amp;quot;:0,&amp;quot;2&amp;quot;:0,&amp;quot;3&amp;quot;:3},{&amp;quot;1&amp;quot;:1,&amp;quot;2&amp;quot;:0,&amp;quot;4&amp;quot;:1}]},&amp;quot;11&amp;quot;:4,&amp;quot;12&amp;quot;:0}"&gt;Why don't you trigger your workflow directly when a new deal is created so that at one instance it will run only for that one particular deal.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P data-unlink="true"&gt;&lt;SPAN&gt;Hope this helps!&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If we were able to answer your query, kindly help the community by marking it as a solution.&lt;BR /&gt;Thanks and Regards.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 08:37:36 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/569232#M50625</guid>
      <dc:creator>webdew</dc:creator>
      <dc:date>2022-02-04T08:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: Errors when enrolling many objects into a custom code workflow step</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/569823#M50658</link>
      <description>&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hundreds of deals are enrolling at the same time which is making the search API hit its limit of 4 requests per second.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need a way for the workflow to *sequentially* processed the deals with a delay between each run of the workflow.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Feb 2022 23:19:07 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/569823#M50658</guid>
      <dc:creator>WaydeChristie1</dc:creator>
      <dc:date>2022-02-04T23:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: Errors when enrolling many objects into a custom code workflow step</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/637181#M53449</link>
      <description>&lt;P&gt;&lt;FONT size="3"&gt;Commenting here as I had a similar case with a customer: &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;FONT size="3"&gt;From checking in with our product team, we confirmed that there isn't a way of staggering workflow enrollments at the moment (i.e. if many objects are being enrolled into the same time, they can't be processed or staggered with a few seconds or minutes apart).&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT size="3"&gt;I'd suggest posting a new idea for this and&amp;nbsp;sharing your use case with us over in the&amp;nbsp;&lt;SPAN&gt;&lt;SPAN&gt;&lt;A href="https://community.hubspot.com/t5/HubSpot-Ideas/idb-p/HubSpot_Ideas" target="_blank" rel="nofollow noopener noreferrer"&gt;Ideas forum here&amp;nbsp;&lt;/A&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;which will hopefully let our product team know.&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;FONT size="3"&gt;In the meantime, the only way around this is to adjust the process you're using to enroll objects into the workflow. Some possible options:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;FONT size="3"&gt;It sounds like you might be enrolling deals based on an automatic enrollment trigger set up in the workflow, so you could instead remove the trigger and&amp;nbsp;manually enroll contacts. This way, you can choose how many objects you want to enroll at once. If you want to continue using an enrollment trigger, being more specific with the trigger and basing it off different property values might help.&lt;/FONT&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;FONT size="3"&gt;You can also try to experiment with your&amp;nbsp;&lt;A style="font-family: inherit; background-color: #ffffff;" href="https://knowledge.hubspot.com/workflows/manage-your-workflow-settings#set-times-for-actions-to-execute" target="_blank" rel="nofollow noopener"&gt;action execution settings - see documentation here.&amp;nbsp;&lt;/A&gt;If the workflow only executes actions during specific time frames throughout each day, you may be able to reduce the amount of objects attempting to go through the workflow actions simultaneously.&lt;/FONT&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&lt;FONT size="3"&gt;That said, while the above are some suggestions, there isn't any single "best" option here as this will depend on your specific needs. Hope this helps to point you in the right direction! &lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="3"&gt;&lt;STRONG&gt;If this post helped, please mark it as a solution to help more users.&amp;nbsp;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 May 2022 08:40:41 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/637181#M53449</guid>
      <dc:creator>JacquelineOng</dc:creator>
      <dc:date>2022-05-23T08:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: Errors when enrolling many objects into a custom code workflow step</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/655077#M54375</link>
      <description>&lt;P&gt;Hey Wayde - did you ever find a solution for this? I have a similar challenge right now. Thanks, Phil&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 14:21:53 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/655077#M54375</guid>
      <dc:creator>PBaxter</dc:creator>
      <dc:date>2022-06-24T14:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: Errors when enrolling many objects into a custom code workflow step</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/655725#M54401</link>
      <description>&lt;P&gt;Hi Phil - unfortunately not. Until Hubspot builds a way to sequentially step objects through a workflow, I don't think it will be possible.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Jun 2022 23:05:03 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/655725#M54401</guid>
      <dc:creator>WaydeChristie1</dc:creator>
      <dc:date>2022-06-26T23:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: Errors when enrolling many objects into a custom code workflow step</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/903343#M70206</link>
      <description>&lt;P&gt;Zapier now has a nicely implemented delay method based on a very simple queue - essentially all enrolled objects get pushed onto a queue and then released every 'x' seconds/minutes. It'd be good if HubSpot could pick up something similar. It's getting more acute as an issue as leveraging the OpenAI API for example is super difficult without better control of rates&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the meantime, I'm now using that zapier delay/queue step as a work-round in a number of workflows.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jan 2024 10:57:32 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/903343#M70206</guid>
      <dc:creator>PBaxter</dc:creator>
      <dc:date>2024-01-10T10:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: Errors when enrolling many objects into a custom code workflow step</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/1010314#M75029</link>
      <description>&lt;P&gt;Hi Everyone,&lt;BR /&gt;&lt;BR /&gt;I know this post is a bit older now, but I thought I'd add a solution for anyone that's having similar issues.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;The issue with using any HubSpot delays is that if all the objects are enrolled at the same time, for example when an import is done they will hit the delay stage at the same time, therefore they will all still hit your custom coded step at the same time, not resolving the limit issue.&lt;BR /&gt;&lt;BR /&gt;What I suggest doing is an exponentially increasing randomised delay using setTimeout(). I've put an example of how this can be done below:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{

  let timeout = 5000;
  const maxTries = 5;
  let outcome = 0;
  let data;

  for (let i = 1; i &amp;lt;= maxTries; i++) {
    const response = await fetch(url, options);
    if (response.status === 200) {
      data = await response.json();
      outcome = 200;
      break;
    } else {
      console.log(`Attempt ${i} failed. Retrying in ${timeout}ms...`);
      await new Promise(resolve =&amp;gt; setTimeout(resolve, timeout));
      timeout *= 3*Math.random();
    }
  }

  if (outcome !== 200) {
    throw new Error(`Max retries reached. Unable to fetch data.`);
  }
  
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you can see, everytime the response fails, it multiples the delay anywhere from 0-3 times and retries up to 5 times before erroring.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;For the timing I would suggest finding out what you're largest import/creation event would be and see what timeframe this would need to be split over to be within the rate limit.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Jul 2024 03:20:48 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/1010314#M75029</guid>
      <dc:creator>HubSpot_Corey</dc:creator>
      <dc:date>2024-07-16T03:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: Errors when enrolling many objects into a custom code workflow step</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/1045749#M76901</link>
      <description>&lt;P&gt;Echoing that this is an older post, btu the problem seems to persist. I finally decided to just add a multiple custom code steps with ONLY randomly-generated wait times. So the whole step just looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;exports.main = async (event) =&amp;gt; {

  // The number io line 6 represents time in milliseconds.
  // So 15000 = 15 seconds. You can go up or down,
  // but it will time out automatically if you go over 20000.
  let timeInMs = Math.random() * (15000);

  let test = function (){
      console.log('Waited ' + timeInMs)
  };
  setTimeout(test,timeInMs);
  
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I added in three of these at the beginning of my workflow. Nothing fancy, at all, but it seems to smooth the rough edges enough.&lt;BR /&gt;&lt;BR /&gt;Note: this is technically commented above, but I'd stay under 15000 or so in real-world applicaitons. 15000 is probably about as high as I'd go since custom code has to execute in 20 seconds or less.&lt;/P&gt;</description>
      <pubDate>Wed, 25 Sep 2024 13:22:48 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Errors-when-enrolling-many-objects-into-a-custom-code-workflow/m-p/1045749#M76901</guid>
      <dc:creator>Clare_HS</dc:creator>
      <dc:date>2024-09-25T13:22:48Z</dc:date>
    </item>
  </channel>
</rss>

