Get Loyalty Account

getLoyaltyAccount is used to search for a customer loyalty account by phone number.

Please note, if the merchant has customer accounts enabled on their Square Online site, the CustomerAccount template resource will include the customer’s loyalty account details. This SDK function is provided in cases where the merchant does not have customer accounts enabled on their site.

Usage

getLoyaltyAccount takes in the following object.

interface GetLoyaltyAccountRequest {
    phone: string;
}

The phone field is the phone number of the customer you want to search for. It must include the country code and be in E.164 format, e.g. “+12125554250”

Example

try {
    const response = await sdk.customers.getLoyaltyAccount({ phone: '+12125554250' });
    if (response.data) {
        const loyaltyAccount = response.data;
    } else {
        // No loyalty account found
    }
} catch (error) {
    // Handle errors
}

Return Value

When a loyalty account is found, a GetLoyaltyAccountResponse object is returned.

interface GetLoyaltyAccountResponse {
    data: LoyaltyAccount;
}

interface LoyaltyAccount {
    id: string;
    program_id: string;
    balance: number;
    lifetime_points: number;
}

If no loyalty account is found, an empty object is returned.

interface NoLoyaltyAccountResponse {
}

Error Handling

Note: No error is thrown if a loyalty account is not found.

The SDK has no special error handling for this GET request. On a network error, it will simply throw the Error object that fetch would throw.