Step 1: Authenticate

Authentication is the most important step of the process and it involves:

  • Getting your Auth header
  • Making your first API call
  • Adding a company

Get your Auth header

Codat uses API keys to control access to the API. The API key needs to be included in all API requests to the server, Base64 encoded within an "Authorization" header: Authorization: Basic your_encoded_api_key.

Auth headers can only be viewed and copied by users with Administrator or Developer roles.

Copy your Auth header from the Codat for developers section on the Learn and Build page. You will need it to complete the next steps.

Make your first API call using Swagger

Add your authorization header to Swagger

  1. Select Explore Swagger to go to Codat's Swagger page.
  2. Select Authorize.
  3. Enter the Auth header in the Value box and authorize your connection.
Authorize in SwaggerAuthorize in Swagger

Authorize in Swagger

Use Swagger's "Try it out" to interact with an endpoint

  1. Click Companies to view the endpoints available for interacting with companies.
  2. Select GET /companies to view details about the list all companies endpoint and then Try it out.
  3. Enter 1 for the page.
  4. Select Execute.

You'll see the API response in the Responses section.

Make your first API call in code

  1. Create a new REST client using as the base URL.
  2. Add an Authorization header using the value you copied above.
  3. Create a GET request for the /companies endpoint.
  4. Execute the request.
//using RestSharp;

var baseUrl = "";
var authHeaderValue = "Basic ABCDEF1234567890";

//Create a RestClient using the Codat API's base URL
var codatApiClient = new RestClient(baseUrl);

//Add your authorization header
codatApiClient.AddDefaultHeader("Authorization", authHeaderValue);

//Create a GET request
var getCompaniesRequest = new RestRequest("companies", Method.GET);
getCompaniesRequest.AddQueryParameter("page", "1");

//Execute the request
var getCompaniesResponse = codatApiClient.Execute(getCompaniesRequest);
import requests

baseUrl = ''
authHeaderValue = 'Basic ABCDEF1234567890=='

getCompaniesUrl = baseUrl + 'companies?page=1&pageSize=100'
requestHeaders = {'Authorization' : authHeaderValue}

getCompaniesResponse = requests.get(getCompaniesUrl, headers=requestHeaders)

Did this page help you?