Function getAccessToken

  • Obtains an access token using client credentials and an authorization code.

    Parameters

    • clientId: string

      The client ID of your application.

    • clientSecret: string

      The client secret of your application.

    • redirectUri: string

      The redirect URI specified in your application.

    • code: string

      The authorization code returned after successful user authorization.

    Returns Promise<AccessToken>

    A promise resolving to an AccessToken object.

    When a user authenticates your application, an authorization code is provided. This function exchanges that code for an access token, which can be used to make authorized requests to the Donation Alerts API.

    HttpError If an error occurs during the request, such as invalid credentials.

    try {
    const accessToken = await getAccessToken(
    'your-client-id',
    'your-client-secret',
    'http://your-redirect-uri',
    'authorization-code'
    );

    console.log('Access Token:', accessToken.accessToken);
    } catch (e) {
    console.error('Failed to get access token:', e);
    }