Skip to main content

Manage companies with our API

Learn about creating and managing companies, their connections, and their data via API

Onboard your users

Your users or customers are companies. To access their data you'll need to onboard them.

To onboard a new user or customer:

  1. Create a company
  2. Authorize access to sources of data
  3. Read the data

You can either onboard users:

  • When they first create an account with your service
  • At the first point you want to retrieve their financial data

Create a company

To create a new company, use the Create company endpoint and provide a name for the company in the request body. The name parameter is mandatory to execute this request. You can also provide a description to store additional information about the company.

platformClient.companies.create({
name: "Toft stores",
description: "Need a loan for refurb."
}).then((companyCreatedRes: CreateCompanyResponse) => {
if (companyCreatedRes.statusCode == 200) {
console.log(companyCreatedRes.company.id, companyCreatedRes.company.name)
}
});
Retain the company ID

The id property that you receive in the response is the unique Codat identifier for this company. We recommend that you retain it for future reference.

Company name

The name of the company helps you identify the company in the Codat Portal and doesn't have to be unique. Make sure to avoid forbidden characters.

Add metadata to a company

You can enrich a company profile with additional information using the tags object. These tags provide flexible ways to store metadata.

For example, you can set foreign key associations, define operational regions, or record specific details about the financial services a company has requested.

Each company can have up to 10 tags that you can add using the Create company endpoint or when updating the company via the Update company endpoint.

Use tags with webhooks

You can use the tags object to filter companies to specific webhook consumers. To learn more, see Filter webhooks by company tags.

For example, here's how you can add tags that define a user-defined ID (UID) and operating region:

platformClient.companies.create({
name: "Toft stores",
tags: {
uid: "cust_1MtJUT2eZvKYlo2CNaw2HvEv",
region: "uk"
}
}).then((companyCreatedRes: CreateCompanyResponse) => {
if (companyCreatedRes.statusCode == 200) {
console.log(companyCreatedRes.company.id, companyCreatedRes.company.name)
}
});
Updating a company with existing tags

If you use include a null or empty tags object in the Update company endpoint request, any existing tags for this company will be removed. To retain existing tags, ensure they are included in the update.

Authorize access to company data

Once you've created the company, they'll need to give you permission to read their data from a given source, like their accounting software. There are several approaches to doing this, but for simplicity we've just covered our out-of-the-box hosted link approach.

Send the user to the redirect URL returned in the previous step. They will be sent to Link where they can select their accounting software and complete the linking process.

Once the user has completed the Link flow, the Codat platform will redirect them to the redirect URL you have configured in the Settings > Auth flow > Link in the Codat Portal. This URL can include the Codat companyId as well as any other custom query parameters.

Redirect parameter settings

For more information on setting your redirect URL, refer to this document.

Once your user is redirected to the redirect URL page, they'll be able to authorize access to their data. Once this is successful, the linking process is complete and their data can be read.

Re-authorize access

Occasionally the Data Connections of a Codat company will go into a deauthorized state. This indicates that Codat’s link to the platform is no longer valid, and you will not be able to queue any further data syncs for that connection. You will still be able to query data previously retrieved from the platform.

Data Connections can become deauthorized by the user revoking access to their accounting software or due to platform limitations such as Xero's limited access period for non-partner companies.

To enable you to refresh the company's data, you will need to ask the user to complete the auth flow in Link again.

Re-linking and usage costs

Creating a new company may cause additional data to be read from the platform and is likely to incur additional usage costs.

Redirect the user to complete the auth flow

Get a redirect URL for the company by following the process here. Send the user to the redirect URL. They will be prompted to select their accounting software and complete the linking process using the Link flow.

Once the user finishes the Link flow, they will be redirected back to the Redirect URL, as described earlier in this guide. At this point the re-authorization process is complete and their data has begun synchronizing again.

Delete companies

You can delete a company and its data using the Delete company endpoint.

const companyDeleteResponse = await platformClient.companies.delete({
companyId: companyCreatedRes.company.id,
});
Recap

You've learned:

  • How to create a company and authorize access to their data
  • The basics of reading data
  • Manage companies


Was this page useful?
👏
👍
🤔
👎
😭