A lightweight wrapper for making API calls to Donation Alerts.
This package provides simple utilities for sending requests to various Donation Alerts API endpoints using provided credentials. Although it is mainly intended for internal use, some of its utilities may prove useful in your own code. For a more flexible and feature-rich experience with the Donation Alerts API, consider using the @donation-alerts/api package.
npm
:npm i @donation-alerts/api-call
yarn
:yarn add @donation-alerts/api-call
pnpm
:pnpm add @donation-alerts/api-call
You can call the Donation Alerts API in two ways:
Using callDonationAlertsApiRaw()
: This function returns the native Response
object from the Fetch API.
Using callDonationAlertsApi<T>()
: This function returns only the payload data, which you can type via the generic parameter T
.
Both functions accept the following arguments:
options
: DonationAlertsApiCallOptionsaccessToken
(optional): stringfetchOptions
(optional): DonationAlertsCallFetchOptionsTo fetch raw data from the alerts/donations
endpoint:
import { callDonationAlertsApiRaw } from '@donation-alerts/api-call';
// Within an async function or when using top-level await:
const response = await callDonationAlertsApiRaw(
{
url: 'alerts/donations',
},
'<YOUR_ACCESS_TOKEN>',
);
// 'response' is the native Response object from the Fetch API.
To receive only the mapped payload data, you can do the following:
import { callDonationAlertsApi } from '@donation-alerts/api-call';
// Define an interface representing the expected payload.
interface PayloadData {
// ...
}
const response = await callDonationAlertsApi<PayloadData>(
{
url: '<endpoint>',
},
'<YOUR_ACCESS_TOKEN>',
);
// 'response' is mapped to the PayloadData interface.
The above function may throw an HttpError, which you should catch and handle accordingly.
For more detailed information, please refer to the documentation.