Edits history of script submission #4339 for ' Searches for gift cards (shopify)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Shopify = {
      token: string;
      store_name: string;
    };
    /**
     * Searches for gift cards
     * Searches for gift cards that match a supplied query. The following fields are indexed by search:  created_at updated_at disabled_at balance initial_value amount_spent last_characters  Note: As of version 2019-10, this endpoint implements pagination by using links that are provided in the response header. Sending the page parameter will return an error. To learn more, see Making requests to paginated REST Admin API endpoints.
     */
    export async function main(
      auth: Shopify,
      api_version: string = "2023-10",
      order: string | undefined,
      query: string | undefined,
      limit: string | undefined,
      fields: string | undefined
    ) {
      const url = new URL(
        `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/gift_cards/search.json`
      );
      for (const [k, v] of [
        ["order", order],
        ["query", query],
        ["limit", limit],
        ["fields", fields],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          "X-Shopify-Access-Token": auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 396 days ago

  • nativets
    type Shopify = {
      token: string;
      store_name: string;
    };
    /**
     * Searches for gift cards
     * Searches for gift cards that match a supplied query. The following fields are indexed by search:  created_at updated_at disabled_at balance initial_value amount_spent last_characters  Note: As of version 2019-10, this endpoint implements pagination by using links that are provided in the response header. Sending the page parameter will return an error. To learn more, see Making requests to paginated REST Admin API endpoints.
     */
    export async function main(
      auth: Shopify,
      api_version: string = "2023-10",
      order: string | undefined,
      query: string | undefined,
      limit: string | undefined,
      fields: string | undefined
    ) {
      const url = new URL(
        `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/gift_cards/search.json`
      );
      for (const [k, v] of [
        ["order", order],
        ["query", query],
        ["limit", limit],
        ["fields", fields],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          "X-Shopify-Access-Token": auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 942 days ago