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
Do not query
publishedOnCurrentPublicationnode forpublishableobject and it will work.