Edits history of script submission #4465 for ' Retrieves a count of smart collections (shopify)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Shopify = {
      token: string;
      store_name: string;
    };
    /**
     * Retrieves a count of smart collections
     * Retrieves a count of smart collections
     */
    export async function main(
      auth: Shopify,
      api_version: string = "2023-10",
      title: string | undefined,
      product_id: string | undefined,
      updated_at_min: string | undefined,
      updated_at_max: string | undefined,
      published_at_min: string | undefined,
      published_at_max: string | undefined,
      published_status: string | undefined
    ) {
      const url = new URL(
        `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/smart_collections/count.json`
      );
      for (const [k, v] of [
        ["title", title],
        ["product_id", product_id],
        ["updated_at_min", updated_at_min],
        ["updated_at_max", updated_at_max],
        ["published_at_min", published_at_min],
        ["published_at_max", published_at_max],
        ["published_status", published_status],
      ]) {
        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;
    };
    /**
     * Retrieves a count of smart collections
     * Retrieves a count of smart collections
     */
    export async function main(
      auth: Shopify,
      api_version: string = "2023-10",
      title: string | undefined,
      product_id: string | undefined,
      updated_at_min: string | undefined,
      updated_at_max: string | undefined,
      published_at_min: string | undefined,
      published_at_max: string | undefined,
      published_status: string | undefined
    ) {
      const url = new URL(
        `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/smart_collections/count.json`
      );
      for (const [k, v] of [
        ["title", title],
        ["product_id", product_id],
        ["updated_at_min", updated_at_min],
        ["updated_at_max", updated_at_max],
        ["published_at_min", published_at_min],
        ["published_at_max", published_at_max],
        ["published_status", published_status],
      ]) {
        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