Edits history of script submission #20565 for ' BatchRetrieveInventoryCounts (square)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Square = {
      token: string;
    };
    /**
     * BatchRetrieveInventoryCounts
     * Returns current counts for the provided
    [CatalogObject]($m/CatalogObject)s at the requested
    [Location]($m/Location)s.
    
    Results are paginated and sorted in descending order according to their
    `calculated_at` timestamp (newest first).
    
    When `updated_after` is specified, only counts that have changed since that
    time (based on the server timestamp for the most recent change) are
    returned. This allows clients to perform a "sync" operation, for example
    in response to receiving a Webhook notification.
     */
    export async function main(
      auth: Square,
      body: {
        catalog_object_ids?: string[];
        location_ids?: string[];
        updated_after?: string;
        cursor?: string;
        states?:
          | "CUSTOM"
          | "IN_STOCK"
          | "SOLD"
          | "RETURNED_BY_CUSTOMER"
          | "RESERVED_FOR_SALE"
          | "SOLD_ONLINE"
          | "ORDERED_FROM_VENDOR"
          | "RECEIVED_FROM_VENDOR"
          | "IN_TRANSIT_TO"
          | "NONE"
          | "WASTE"
          | "UNLINKED_RETURN"
          | "COMPOSED"
          | "DECOMPOSED"
          | "SUPPORTED_BY_NEWER_VERSION"
          | "IN_TRANSIT"[];
        limit?: number;
      },
    ) {
      const url = new URL(
        `https://connect.squareup.com/v2/inventory/counts/batch-retrieve`,
      );
    
      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