Edits history of script submission #20803 for ' SearchTerminalCheckouts (square)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Square = {
      token: string;
    };
    /**
     * SearchTerminalCheckouts
     * Returns a filtered list of Terminal checkout requests created by the application making the request. Only Terminal checkout requests created for the merchant scoped to the OAuth token are returned. Terminal checkout requests are available for 30 days.
     */
    export async function main(
      auth: Square,
      body: {
        query?: {
          filter?: {
            device_id?: string;
            created_at?: { start_at?: string; end_at?: string };
            status?: string;
          };
          sort?: { sort_order?: "DESC" | "ASC" };
        };
        cursor?: string;
        limit?: number;
      },
    ) {
      const url = new URL(
        `https://connect.squareup.com/v2/terminals/checkouts/search`,
      );
    
      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