Edits history of script submission #20564 for ' BatchRetrieveInventoryChanges (square)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Square = {
      token: string;
    };
    /**
     * BatchRetrieveInventoryChanges
     * Returns historical physical counts and adjustments based on the
    provided filter criteria.
    
    Results are paginated and sorted in ascending order according their
    `occurred_at` timestamp (oldest first).
    
    BatchRetrieveInventoryChanges is a catch-all query endpoint for queries
    that cannot be handled by other, simpler endpoints.
     */
    export async function main(
      auth: Square,
      body: {
        catalog_object_ids?: string[];
        location_ids?: string[];
        types?: "PHYSICAL_COUNT" | "ADJUSTMENT" | "TRANSFER"[];
        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"[];
        updated_after?: string;
        updated_before?: string;
        cursor?: string;
        limit?: number;
      },
    ) {
      const url = new URL(
        `https://connect.squareup.com/v2/inventory/changes/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