Typescript/Javascript

We provide SDKs for most of our APIs that are automatically generated by our automation pipeline. Each APIs generate its own SDK:

Since each SDK is generated, they only contains their specific endpoints definition without handling authentication. To avoid bothering with this when using made, we made @rlvt/openapi-client-utils which export a single createClient method that have the following options:

export type getClientOptions = { // the type of client to which you will give the result of `createClient` type: ClientType, // your client id given by Reelevant Team clientId: string, // how to authenticate with Reelevant authenticationType: AuthenticationType, // Called when we get a 401 from gateway, which means we need to re-authenticate using // whatever `grant_type` you configured onAuthenticationRequired?: (options: { currentTokens: Partial<Tokens>, options: getClientOptions, request: AxiosRequestConfig }) => Promise<Tokens>, // Called when, even after `onAuthenticationRequired`, we still get a 401. // Generally require to give a new refresh_token onAuthenticationFailure?: (error: Error) => void, // Called when we succesfully authenticate or re-authenticate, used for debugging. onAuthenticationSuccess?: (profile: SerializedUser) => void }

Note that onAuthenticationRequired, onAuthenticationFailure and onAuthenticationSuccess are optional and should only be used if you don't want to either login with a refresh token or an username/password.

To authenticate you have two choice of configuration for authenticationType:

createClient({ type: ClientType.WORKFLOWS, clientId: "<clientId>", authenticationType: { type: 'refresh_token', // using a refresh token that you can get by posting on /v2/auth/token // see https://reelevant.readme.io/reference/get-token (1st option) refreshToken: process.env.REFRESH_TOKEN as string } }

Or you can use a plain username/password:

createClient({ type: ClientType.WORKFLOWS, clientId: "<clientId>", authenticationType: { type: 'password', email: process.env.EMAIL as string, password: process.env.PASSWORD as string } }

Workflows SDK

In this example, we use the sdk to retrieve the list of workflows:

import { createClient, ClientType } from '@rlvt/openapi-client-utils' import WorkflowsSDK from '@rlvt/workflows-openapi-client' const workflowSDK = new WorkflowsSDK(createClient({ type: ClientType.WORKFLOWS, clientId: "<clientId>", authenticationType: { type: 'refresh_token', refreshToken: process.env.REFRESH_TOKEN as string } })) const run = async () => { const list = await workflowSDK.Workflow.list({}) console.log(list.data.data) } run().then(() => console.log('Done.')).catch(err => console.error(err.message, err!.response.data))

Datasources SDK

In this example, we setup the sdk to retrieve the list of datasources:

import DatasourceSDK, { DatasourceStatus } from '@rlvt/datasources-openapi-client' import { createClient, ClientType } from '@rlvt/openapi-client-utils' const sdk = new DatasourceSDK(createClient({ type: ClientType.DATASOURCES, clientId: "<clientId>", authenticationType: { type: 'refresh_token', refreshToken: process.env.REFRESH_TOKEN as string } })) const run = async () => { const res = await sdk.Datasource.list({ perPage: 5, status: [DatasourceStatus.PUBLISHED] }) console.log(res.data) } run().then(() => console.log('Done.')).catch(err => console.error(err))

Contents SDK

In this example, we use the sdk to retrieve the list of contents:

import { createClient, ClientType } from '@rlvt/openapi-client-utils' import ContentsSDK from '@rlvt/contents-openapi-client' const contentsSDK = new ContentsSDK(createClient({ type: ClientType.CONTENTS, clientId: "<clientId>", authenticationType: { type: 'refresh_token', refreshToken: process.env.REFRESH_TOKEN as string } }) as any) const run = async () => { const list = await contentsSDK.Content.list({}) console.log(list.data.data) } run().then(() => console.log('Done.')).catch(err => console.error(err.message, err!.response.data))