Edits history of script submission #20622 for ' CreateLoyaltyAccount (square)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Square = {
      token: string;
    };
    /**
     * CreateLoyaltyAccount
     * Creates a loyalty account. To create a loyalty account, you must provide the `program_id` and a `mapping` with the `phone_number` of the buyer.
     */
    export async function main(
      auth: Square,
      body: {
        loyalty_account: {
          id?: string;
          program_id: string;
          balance?: number;
          lifetime_points?: number;
          customer_id?: string;
          enrolled_at?: string;
          created_at?: string;
          updated_at?: string;
          mapping?: { id?: string; created_at?: string; phone_number?: string };
          expiring_point_deadlines?: { points: number; expires_at: string }[];
        };
        idempotency_key: string;
      },
    ) {
      const url = new URL(`https://connect.squareup.com/v2/loyalty/accounts`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago