Best Practices for Making API Calls to CircleCI Through a Script


Sometimes it may be necessary to make calls to the CircleCI API before, after, or during execution. The best way to achieve this is typically through the use of script. Scripts can be useful, but in order to use them effectively, we recommend following some best practices.


Best Practices:

  • Ensure that the service or machine your script executes from has a Static IP 
    • If your IP changes constantly, or you go through a third-party provisioning service that serves IPs as calls are made, you may be erroneously blocked by Cloudflare. This is due to the fact that the range of the IP you may be served could be on a blocklist we pull from. Maintaining one static IP will help mitigate this
  • Keep your API token up-to-date
    • As security practices evolve, keeping one token that you use for months, or years at a time will be unreliable. Many API call errors are red herrings for the real issue of having an outdated token.
  • Add exponential backoffs to calls that receive 403 / 429
    • An exponential backoff is a type of algorithm that will decrease the number of retries that your script will perform when you begin to see errors in your calls. This can help decrease the chance of being rate limited or blocked altogether.


Additional Resources:

Was this article helpful?
0 out of 0 found this helpful



Article is closed for comments.