Edits history of script submission #4551 for ' Creates a theme (shopify)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Shopify = {
      token: string;
      store_name: string;
    };
    /**
     * Creates a theme
     * Creates a theme by providing the public URL of a ZIP file that contains the theme. A new theme is always unpublished by default. To publish a theme when you create it, include "role": "main" in the POST request. The theme will be published only after all of its files have been extracted and stored by Shopify, which might take a couple of minutes.
     */
    export async function main(
      auth: Shopify,
      api_version: string = "2023-10",
      body: {
        theme?: { body?: string; [k: string]: unknown };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/themes.json`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "X-Shopify-Access-Token": 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 396 days ago

  • nativets
    type Shopify = {
      token: string;
      store_name: string;
    };
    /**
     * Creates a theme
     * Creates a theme by providing the public URL of a ZIP file that contains the theme. A new theme is always unpublished by default. To publish a theme when you create it, include "role": "main" in the POST request. The theme will be published only after all of its files have been extracted and stored by Shopify, which might take a couple of minutes.
     */
    export async function main(
      auth: Shopify,
      api_version: string = "2023-10",
      body: {
        theme?: { body?: string; [k: string]: unknown };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/themes.json`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "X-Shopify-Access-Token": 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 942 days ago