skip to Main Content

When we created a API, I figured that I need to configure a new Shopify like this

const Shopify = require('shopify-api-node');

const shopify = new Shopify({
  shopName: 'your-shop-name',
  apiKey: 'your-api-key',
});

Is there any way to get the Shopify "your-shop-name" programmatically? So If I installed the app on another one it won’t need to change. Or is there any other way to configure the API on Shopify?

I primarily need to update the product description using Admin REST API.

2

Answers


  1. In your store, where you want to change descriptions using API calls, use the Admin App section to issue yourself an API key pair. You can give that key pair permission to edit products. And you’re done! You have the store name obviously, and you have your access token. Nothing to it!

    Login or Signup to reply.
  2. Yes, there is a way to retrieve the Shopify shop name programmatically without hardcoding it in your API configuration. When you install your app on a Shopify store, you can access the shop’s information through the authentication process. Here’s how you can retrieve the shop name dynamically:

    During the app installation process, when the merchant authorizes your app, Shopify will redirect them to a specified callback URL along with an access token.

    In your callback URL or subsequent API requests, you can use the access token to make authenticated requests to the Shopify API.

    When making API requests, you can include the X-Shopify-Access-Token header with the access token value.

    With a valid access token, you can use the Shopify API’s /admin/shop.json endpoint to retrieve the shop’s information, including the shop name.

    Here’s an example using the axios library in Node.js to make the request:

    const axios = require(‘axios’);

    axios({
    method: ‘GET’,
    url: ‘https://your-shop-name.myshopify.com/admin/shop.json’,

    In the above example, replace ‘your-shop-name’ with the shop’s permanent domain (e.g., example.myshopify.com), and ‘your-access-token’ with the valid access token obtained during the authentication process.

    By retrieving the shop name dynamically, you can use the same code and configuration for multiple Shopify installations without the need to hardcode the shop name.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search