Changing the Merchant's Storefront/Online Store

Changing the Merchant's Storefront/Online Store

Zarsalan
Shopify Partner
1 0 0

Hey, 

 

I am working on an app that interacts with the merchant's online store and changes it. I use the REST API Asset to change the online store, but I get a 404 Error whenever I hit the PUT or DEl API. Is there any fix for this, I am following the REST API guidelines to perfection and using the code snippets, but it just doesn't seem to work. I even tried using different API versions, but that doesn't work either.

 

This is my code for the PUT and DEL request:

 

 

userRoutes.get("/getTheme", async (req, res) => {
  console.log("GET Themes API Hit");
  const { client } = await clientProvider.restClient({
    req,
    res,
    isOnline: true,
  });
  const getTheme = await client.get({ path: "themes" });
  const themeID = getTheme.body.themes[0].id;
  console.log(getTheme.body.themes[0].id);

  const getAssets = await client.get({ path: `themes/${themeID}/assets` });
  console.log(getAssets.body.assets);

  console.log("DEL Assets API Hit");
  const del = await shopify.rest.Asset.delete({
    session: res.locals.user_session,
    theme_id: "163343204627",
    asset: { key: "assets/collage.css" },
  });
  console.log(del);

  console.log("PUT Assets API Hit");
  const asset = new shopify.rest.Asset({ session: res.locals.user_session });
  asset.theme_id = themeID;
  asset.key = "templates/index.liquid";
  asset.value =
    "<p>We are busy updating the store for you and will be back within the hour.</p>";

  await asset.save({ update: true });
  //   console.log(asset);

  return res.status(200).json({ theme: getTheme.body.themes });
});

 

 

And I get this error:

throw new ShopifyErrors.HttpResponseError({
[server]                       ^
[server] 
[server] HttpResponseError: Received an error response (404 Not Found) from Shopify:
[server] "Not Found"
[server] If you report this error, please include this id: 8dfd185b-8a85-4a4b-b89a-451bc8c6f527
[server]     at NewRestClient.throwFailedRequest (/Users/zohaibarsalan/Developer/bannerito/node_modules/@shopify/shopify-api/lib/clients/http_client/http_client.js:193:23)
[server]     at NewRestClient.<anonymous> (/Users/zohaibarsalan/Developer/bannerito/node_modules/@shopify/shopify-api/lib/clients/http_client/http_client.js:220:22)
[server]     at Generator.next (<anonymous>)
[server]     at fulfilled (/Users/zohaibarsalan/Developer/bannerito/node_modules/tslib/tslib.js:166:62)
[server]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
[server]   response: {
[server]     code: 404,
[server]     statusText: 'Not Found',
[server]     body: { errors: 'Not Found' },

Is there any fix for this? If not is there a better way for me to interact with the online store via JS in the form of an embedded app? 

I would appreciate help as I have been stuck at this for the past 2 days, without any luck. 

Replies 0 (0)