Edits history of script submission #4372 for ' Retrieves a single province for a country (shopify)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Shopify = {
      token: string;
      store_name: string;
    };
    /**
     * Retrieves a single province for a country
     * Retrieves a single province for a country
     */
    export async function main(
      auth: Shopify,
      api_version: string = "2023-10",
      country_id: string,
      province_id: string,
      fields: string | undefined
    ) {
      const url = new URL(
        `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/countries/${country_id}/provinces/${province_id}.json`
      );
      for (const [k, v] of [["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;
    };
    /**
     * Retrieves a single province for a country
     * Retrieves a single province for a country
     */
    export async function main(
      auth: Shopify,
      api_version: string = "2023-10",
      country_id: string,
      province_id: string,
      fields: string | undefined
    ) {
      const url = new URL(
        `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/countries/${country_id}/provinces/${province_id}.json`
      );
      for (const [k, v] of [["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