Edits history of script submission #20791 for ' SearchCatalogObjects (square)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Square = {
      token: string;
    };
    /**
     * SearchCatalogObjects
     * Searches for [CatalogObject]($m/CatalogObject) of any type by matching supported search attribute values,
    excluding custom attribute values on items or item variations, against one or more of the specified query filters.
     */
    export async function main(
      auth: Square,
      body: {
        cursor?: string;
        object_types?:
          | "ITEM"
          | "IMAGE"
          | "CATEGORY"
          | "ITEM_VARIATION"
          | "TAX"
          | "DISCOUNT"
          | "MODIFIER_LIST"
          | "MODIFIER"
          | "PRICING_RULE"
          | "PRODUCT_SET"
          | "TIME_PERIOD"
          | "MEASUREMENT_UNIT"
          | "SUBSCRIPTION_PLAN_VARIATION"
          | "ITEM_OPTION"
          | "ITEM_OPTION_VAL"
          | "CUSTOM_ATTRIBUTE_DEFINITION"
          | "QUICK_AMOUNTS_SETTINGS"
          | "SUBSCRIPTION_PLAN"
          | "AVAILABILITY_PERIOD"[];
        include_deleted_objects?: false | true;
        include_related_objects?: false | true;
        begin_time?: string;
        query?: {
          sorted_attribute_query?: {
            attribute_name: string;
            initial_attribute_value?: string;
            sort_order?: "DESC" | "ASC";
          };
          exact_query?: { attribute_name: string; attribute_value: string };
          set_query?: { attribute_name: string; attribute_values: string[] };
          prefix_query?: { attribute_name: string; attribute_prefix: string };
          range_query?: {
            attribute_name: string;
            attribute_min_value?: number;
            attribute_max_value?: number;
          };
          text_query?: { keywords: string[] };
          items_for_tax_query?: { tax_ids: string[] };
          items_for_modifier_list_query?: { modifier_list_ids: string[] };
          items_for_item_options_query?: { item_option_ids?: string[] };
          item_variations_for_item_option_values_query?: {
            item_option_value_ids?: string[];
          };
        };
        limit?: number;
        include_category_path_to_root?: false | true;
      },
    ) {
      const url = new URL(`https://connect.squareup.com/v2/catalog/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