Getting "Error: Your app doesn't have a publication for this shop." when publishing a product.

Wakil_eFoli
Shopify Partner
43 2 4

When publishing a product to the online store I get the following error:

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

How can I solve this error? 
Replies 3 (3)

Liam
Shopify Staff
2731 302 783

Hi Wakil,

 

Are you using the storefront API?

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Wakil_eFoli
Shopify Partner
43 2 4

At 1st I was using the admin API but now I'm using the storefront API and still no luck.

 

This following code is getting executed in the action:

 

  const { admin } = await authenticate.admin(request);

  const { storefront } = await unauthenticated.storefront( 'test-app.myshopify.com' );

  // Publish the product.
  // const publishProductRequest = await admin.graphql(
  const publishProductRequest = await storefront.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);

 

 

Wakil_eFoli
Shopify Partner
43 2 4

@Liam Can you please tell me why and where should I use the storefront Api?