How to fetch the product ID after creating the product from the API

Highlighted
New Member
6 0 0

Hi all,

I'm using react native and I'm creating a product and then saving it to Shopify but I want to fetch the product ID which I created.(Find the code below)

 How to return the product ID after created in Shopify because I want to update the DB with global product ID.

Thanks in advance.

 
uploadDatatoShopify() {
    console.log("Shopify");

    var data = JSON.stringify({
      "product": {
        "title": this.state.artworkTitle,
        "body_html": this.state.artworkDescription,
        "vendor": this.state.cureentUser.name,
        "product_type": this.state.category,
        "images": [
          {
            "alt": null,
            "src": this.state.links
          }
        ]
      }
    });

    var xhr = new XMLHttpRequest();
    xhr.withCredentials = true;

    xhr.addEventListener("readystatechange", function () {
      if (this.readyState === 4) {
        console.log(this.responseText);
      }
    });

    xhr.open("POST", "username_token and store name//admin/products.json");
    xhr.setRequestHeader("content-type", "application/json");
    xhr.setRequestHeader("x-shopify-access-token", "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");
    xhr.setRequestHeader("cache-control", "no-cache");
     xhr.send(data);
  }
 
0 Likes