BirdSdkApi
The BirdSdkApi class is the main entry point to interact with Bird's API through the SDK. It provides methods to send authenticated requests to the API.
💡 To send an authenticated request, you first need to identify the contact. The scope of the auth token will be defined by the identification claim.
Example
To access the BirdSdkApi, you can use the api property of the SDK instance.
代码示例
Bird.api.fetch('contacts/me');Methods
fetch()
Remarks
The fetch method allows you to send authenticated requests to the Bird API. It can be used in two ways:
- By passing a path as the first argument
- By passing a callback function that receives the workspaceId and the baseUrl and authToken props
fetch(path, opts)
代码示例
fetch<R>(path: string, opts?: FetchOptions): Promise<R>The path overload can be used to define the request with a path and fetch options. Note that all path requests are scoped to the current workspace.
Type Parameters
• R
Parameters
• path: string
The path of the request
• opts?: FetchOptions
Returns
Promise<R>
Example
代码示例
Bird.api.fetch('contacts/me');
// the request will be sent to `/workspaces/{workspaceId}/contacts/me`fetch(callback, options)
代码示例
fetch<Fn>(callback: Fn, options?: undefined): ReturnType<Fn>The callback overload can be used to define the request with a custom fetch function for more control. The callback will receive the workspaceId and the baseUrl and authToken props.
Type Parameters
• Fn extends Callback<Fn>
Parameters
• callback: Fn
The callback function
• options?: undefined
Returns
ReturnType<Fn>
Example
代码示例
Bird.api.fetch((workspaceId, { baseUrl, authToken }) => {
return fetch(`${baseUrl}/workspaces/${workspaceId}/contacts/me`, {
headers: {
Authorization: `Bearer ${authToken}`,
},
});
});