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.

To get your Auth header from the Codat Portal:

  1. In the navigation bar click Settings, and navigate to Organization
  2. In the API access section, copy your Auth header from the Codat for developers box.

You will need your Auth header to complete the next steps.

Make your first API call using Swagger

Add your authorization header to Swagger

  1. On the Welcome page, click Explore Swagger to open Codat's Swagger page in a new browser tab.
  2. Select Authorize in the top-right corner.
  3. In the Available authorizations dialog, paste your Auth header into the Value field.
  4. Click Authorize to authorize your connection.
  5. Close the Available authorizations dialog.
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. Click GET /companies to view details about the "list all companies" endpoint
  3. In the endpoint box, click Try it out. The parameters are now editable.
  4. Enter 1 for the page.
  5. Click Execute.

The API response is returned in the Responses section, next to code 200.

Make your first API call in code

  1. Create a new REST client using https://api.codat.io 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 = "https://api.codat.io";
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 = 'https://api.codat.io/'
authHeaderValue = 'Basic ABCDEF1234567890=='

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

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

Did this page help you?