Error When Publishing A Product To Online Store in Shopify

85 views Asked by At

After creating a product I'm trying to publish it to the online store. The product is getting published but I'm getting the following error:

Error: Your app doesn't have a publication for this shop.

Here is my code:

// Publish the newly created product.
const publishProductRequest = await admin.graphql(
  `#graphql
  mutation publishProduct($id: ID!, $input: [PublicationInput!]!) {
    publishablePublish(id: $id, input: $input) {
      userErrors {
        field
        message
      }
      publishable {
        availablePublicationCount
        publicationCount
        publishedOnCurrentPublication
      }
      shop {
        id
        name
        publicationCount
      }
    }
  }`,
  {
    variables: {
      id: productId,
      input: {
        publicationId: onlineStorePublicationId,
      },
    },
  }
);

const publishProductResponse = await publishProductRequest.json();

return json(publishProductResponse);

However I found a similar question in the Shopify discussion with an accepted solution which is: The app needed storefront API access to set the product to Online Store. But I couldn't comprehend the solution.

Can anyone please help with the issue? TIA

1

There are 1 answers

0
Kovalev Sergii On

Do not query publishedOnCurrentPublication node for publishable object and it will work.

      publishable {
        availablePublicationCount
        publicationCount
      }