LEARNING

How to Get Your Token

Before you Start

Before you can obtain your token, you must first gather your account information. You can retrieve your information through the following guide.

Obtaining your Account Information

Getting Started

Before you can start utilizing the Circle API you must first

To do this you will need to install the current version of NodeJS.

https://nodejs.dev/download

In an IDE of your choice (Visual Studio Code is used for this example) open your terminal.

Shortcut: CTRL + SHIFT + `

We are going to create your project. To do this enter the command npm init in Terminal. The set-up will walk you through the creation steps.

This will generate a package.json file, open the file - then add the following to the scripts section:

"start": "node index.js",

In your project, create a file named index.js if one doesn't already exist.

Before we can start, you will need to install a few dependencies.

  • Axios
  • Crypto

These can be installed by entering the following commands in Terminal:

npm i axios
npm i crypto

Generating your Token

In your index.js file add the dependencies:

const crypto = require('crypto');

const axios = require('axios');

Next we will create the following variable to generate an Epoch Timestamp:

const d = new Date();

Next we will add the following variables that will hold our account information we gathered earlier:

const customerId = "";
const appKey = "";
const endUserId = "";
const nonce = d.getTime();

const secret = "";

Add your account information inside the ""

To get a token you must first Generate a URL. To do this add the following:

const dataToEncrypt = "customerId=" + customerId + "&appKey=" + appKey + "&endUserId=" + endUserId + "&nonce=" + nonce;

const hash = crypto.createHmac('sha256', secret).update(dataToEncrypt).digest('base64');

var url = "https://api.prod-mirror.gocircle.ai/api/token?" + dataToEncrypt + "&signature=" + hash;

This will create a URL that can be used to obtain a token. The token is generated using an axios method:

axios.get(url)
  .then(function (response) {
    let json = "";
    json = JSON.parse(response.data);
    console.log(json);
  })
  .catch(function (error) {
    
    console.log(error);
  })
  .then(function () {
    
  });

And that's it! You can run your script by entering npm start in the Terminal. Your result should look something like this.