Files
kittycad.ts/src/api/api-calls/get_api_call.ts

33 lines
893 B
TypeScript
Raw Normal View History

2022-08-01 14:27:11 +10:00
import fetch from 'node-fetch';
import { ApiCallWithPrice_type, Error_type } from '../../models.js';
import { Client } from '../../client.js';
2022-08-01 14:27:11 +10:00
interface Get_api_call_params {
client?: Client;
id: string;
2022-08-01 14:27:11 +10:00
}
type Get_api_call_return = ApiCallWithPrice_type | Error_type;
2022-08-01 14:27:11 +10:00
export default async function get_api_call({
client,
id,
}: Get_api_call_params): Promise<Get_api_call_return> {
const url = `/api-calls/${id}`;
const urlBase = process?.env?.BASE_URL || 'https://api.kittycad.io';
const fullUrl = urlBase + url;
const kittycadToken = client
? client.token
: process.env.KITTYCAD_TOKEN || '';
2022-08-01 14:27:11 +10:00
const headers = {
Authorization: `Bearer ${kittycadToken}`,
};
const fetchOptions = {
method: 'GET',
2022-08-01 14:27:11 +10:00
headers,
};
const response = await fetch(fullUrl, fetchOptions);
const result = (await response.json()) as Get_api_call_return;
2022-08-01 14:27:11 +10:00
return result;
}