Edits history of script submission #4482 for ' Retrieves the currently logged-in user (shopify)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Shopify = {
      token: string;
      store_name: string;
    };
    /**
     * Retrieves the currently logged-in user
     * Retrieves information about the user account associated with the access token used to make this API request. This request works only when the access token was created for a specific user of the shop.
     */
    export async function main(auth: Shopify, api_version: string = "2023-10") {
      const url = new URL(
        `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/users/current.json`
      );
    
      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 the currently logged-in user
     * Retrieves information about the user account associated with the access token used to make this API request. This request works only when the access token was created for a specific user of the shop.
     */
    export async function main(auth: Shopify, api_version: string = "2023-10") {
      const url = new URL(
        `https://${auth.store_name}.myshopify.com/admin/api/${api_version}/users/current.json`
      );
    
      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