Smart Builder SDK allows us to fetch data from 3rd party APIs that require OAuth authentication. Combined with Apps Authentication we take care of the auth token for you and all you need to worry about is making the API calls using a useful hook: useApiRequest.

Here are some important notes about this hook:

How to use the useApiRequest hook

Make an API call - like this useApiRequest(myCredentialId) - and this returns an object with the following methods:

So, let’s put this hook together with the useAppOauth hook.

Here is a very bare-bones example:

import { useAppOauth, useApiRequest } from 'smart-builder-sdk'

import { manifest } from './my-manifest'

const MY_API = '<https://my-example-api.com/api>';
const { credentialsId } = useAppOauth(manifest.appId);
const { get } = useApiRequest(credentialsId);
// Executes the call
const { data } = await get(`${ MY_API }/list`)