When a request to the Formitize API fails, the API sends back an error. Your integration must read that error and respond to it. Don't ignore it and carry on sending the same request.

You're responsible for what your integration sends

You're responsible for making sure your integration only reads or changes data that your account is allowed to access. That means:

  • the records it works on belong to your company

  • the token or user it uses has permission for the action

  • it stops sending a request once the API has told you it won't succeed

Important: Frequent, repeated requests to view or change data that your account can't access are treated as suspicious. They can look like an attempt to break into an account. If we see this pattern, we may revoke API access for your company.

What an error looks like

Every API response is JSON, with the result inside a payload property. When a request fails, payload contains an error object:


{

  "payload": {

    "error": {

      "message": "No ID was provided.",

      "code": 400,

      "timestamp": 1700000000

    }

  }

}


The HTTP status code is also set to an error code, not 200. Check both: whether the status code is an error, and whether payload.error is present.

Decide what to do from the message, not the status code. Many errors, including permission errors, currently return status 500, so the status code alone doesn't tell you whether retrying could help.

How to handle each kind of error

Error

Message

What to do

Authentication

Invalid token., Invalid company/user/password., Your login has been locked. …, Unable to find HTTP_USER_AGENT

Stop the whole integration and alert someone. Every later request will fail the same way. With a username and password, repeated failures also lock the user out. Fix the credentials before running it again.

Permission

No permission.

Don't retry. The token or user doesn't have access. Log it, alert someone, and fix the permissions in Formitize.

Record doesn't exist or isn't yours

Either this data does not belong to you or does not exist.

Don't retry. Log the ID, remove it from your work queue, and alert someone if it was unexpected. Make sure the same ID isn't requested again on the next run.

Bad request

No ID was provided., or another message about the data you sent

Don't retry unchanged. Fix the data or your code first.

Endpoint not found or not supported

Endpoint not found., Not implemented.

Don't retry. Check the address against the API documentation (Admin > API). If the endpoint isn't documented, it isn't supported.

Temporary problem

No response, a network error or timeout, or an error page that isn't JSON

Retry a few times only, waiting longer each time (e.g. 15, then 30 seconds). If it still fails, stop and alert someone.


Please Note: Only retry requests when the error is likely to be temporary. Requests that fail due to incorrect data or insufficient permissions should be corrected before being resubmitted. Always limit the number of retry attempts to avoid unnecessary API usage.

Example: handling errors in JavaScript

Run this on a server or in a script with Node.js 18 or later, not in a web page.

The example token is shown in the code, so you can see exactly where it goes. In your own integration, don't paste your real token into the code. Store it separately, in an environment variable or secrets store, and have your code read it from there. 


// Fetches one client. Returns null if this client should be skipped.

// Throws if the whole integration should stop.

async function getClient(clientId) {

  for (let attempt = 1; ; attempt++) {

    let response;

    let body;

    try {

      response = await fetch(`https://service.formitize.com/api/rest/v2/crm/client/${clientId}`, {

        headers: { Authorization: "Bearer 1234-3f2b8c1e-9a4d-4e7b-b6c2-0d5e8f1a2b3c" },

        signal: AbortSignal.timeout(30000), // stop waiting after 30 seconds

      });

      body = await response.json();

    } catch (problem) {

      // No response, a timeout, or an error page that isn't JSON. This may be temporary,

      // so try up to 3 times, waiting longer each time (15, then 30 seconds).

      if (attempt === 3) throw problem;

      await new Promise((resolve) => setTimeout(resolve, attempt * 15000));

      continue;

    }


    const error = body.payload?.error;

    if (response.ok && !error) return body.payload;


    const message = error?.message ?? `HTTP ${response.status}`;


    // Wrong or locked credentials: every request will fail. Stop the whole integration.

    if (/^(Invalid token|Invalid company\/user\/password|Your login has been locked|Unable to find HTTP_USER_AGENT)/.test(message)) {

      throw new Error(message);

    }


    // Any other API error: sending the same request again won't help.

    // Log it, skip this client, and remove it from your list so it isn't requested again.

    console.error(`Could not fetch client ${clientId}: ${message}`);

    return null;

  }

}


Call it once for each client, and wait at least a second between calls to stay within the request limit.

This example:

  • checks every response for an error, using payload.error

  • stops the whole integration if the credentials are wrong or the user is locked

  • doesn't retry permission, "does not exist" or bad-request errors

  • retries only temporary problems, trying up to three times with increasing waits, and stops if they keep failing

  • logs each client it skips, so you can remove it from your list

Checklist before you go live

  • Tokens and passwords are read from environment variables or a secrets store, not written in the code.

  • Every response is checked for an error.

  • Errors are logged with the endpoint, the record ID and the message.

  • Someone is alerted when errors happen, by email, chat or a monitoring tool.

  • Authentication errors stop the integration.

  • Permission, "does not exist" and bad-request errors are not retried.

  • Retries are limited and spaced out.

  • Records that failed are not requested again automatically on the next run.

  • All your integrations together stay under 60 requests per minute.