Authentication

Learn how to authenticate with Countercyclical's API.

Overview

All calls to the Countercyclical API require authorization using a Bearer token in the request header:

Authorization: Bearer {token}

Each token is associated to a member with in workspace. As such, users can only work with items within that workspace (along with what's available on their plan).

Generating an API Key

Users can find their API tokens by going to Settings -> Workspace -> Advanced -> Developers -> API Keys.

Each key you generate should look something like the following:

ck_prod_dxjgVIbY...

Be sure to take note of what your generated token is before closing the dialog as you will not be able to view it afterwards.

We recommend storing this value as an environment variable.

Best Practice: Rolling your API Keys

It's a good practice to roll your API keys once in a while for security purposes.

While we do not currently support "rerolling" the same API key, we recommend users generate a new API key with the same permissions they might otherwise have.

To make this easier, you can select from the dropdown menu on the right-hand side of any one of your API keys and select the "Roll as New Key" option.

Example

Here's an example of what a call to get a member's Investments might look like:

import axios, { AxiosResponse } from 'axios';
import { NextFunction, Request, Response, Router } from 'express';

const router = Router();

const apiKey = process.env.COUNTERCYCLICAL_API_KEY;

const countercyclicalAxiosInstance = axios.create({
    baseURL: 'https://api.countercyclical.io',
    headers: {
        Authentication: `Bearer ${apiKey}`,
    },
});

router.get('/v1/investments', async (req: Request, res: Response, next: NextFunction) => {
    try {
        await countercyclicalAxiosInstance
            .get('/v1/investments', { params: { limit: 6 } })
            .then((apiResponse: AxiosResponse) => {
                if (apiResponse.status === 200) {
                    return res.send(apiResponse.data);
                }
            });
    } catch (error) {
        console.error(error);
    }
});

Last updated