Incorrect Location ID When Publishing Product to Multiple Sales Channels

I am currently trying to publish my product to specific sales channels when I create or update a product.

After adding in the productPublications array I’m getting an error about invalid ID, “locations”:

{“data”:{“productUpdate”:null},“errors”:[{“message”:“invalid id”,“locations”:[{“line”:1,“column”:40}],“path”:[“productUpdate”]}],“__lineNumber”:0}

{
  "input": {
    "id": "gid://shopify/Product/XXX",
    "handle": "HANDLE",
    "productPublications": [
      {
        "publicationId": "gid://shopify/Channel/123"
      },
      {
        "publicationId": "gid://shopify/Channel/234"
      }
    ],
    "options": [
      "COLOR",
      "SIZE",
      "WIDTH"
    ],
    "seo": {
      "title": "",
      "description": ""
    },
    "variants": [
      {
        "price": 100,
        "inventoryQuantities": [
          {
            "locationId": "gid://shopify/Location/987",
            "availableQuantity": 1
          }
        ],
      }
    ]
  }
}

However, if I remove the productPublications and use the input below everything works.

{
  "input": {
    "id": "gid://shopify/Product/XXX",
    "handle": "HANDLE",
    "options": [
      "COLOR",
      "SIZE",
      "WIDTH"
    ],
    "seo": {
      "title": "",
      "description": ""
    },
    "variants": [
      {
        "price": 100,
        "inventoryQuantities": [
          {
            "locationId": "gid://shopify/Location/987",
            "availableQuantity": 1
          }
        ],
      }
    ]
  }
}

I have removed most of the other data, and am not using the real shopify IDs for simplicities sake. But am still getting the error with just those few parameters. Is there something I’m missing about attaching sales channels to products? Any advice would be appreciated.

I have verified all the IDs to ensure they are correct. The locations and sales channels’ IDs are all correct.

Thank you

Hi TravisImagine,

Based on the error message, it seems like the problem might be related to the way you are specifying the publicationId in the productPublications array. The publicationId should not be a Channel ID (gid://shopify/Channel/123), but rather an ID of a Publication.

A Publication in Shopify represents the act of publishing a product or collection to a sales channel. Therefore, you need to get the Publication IDs for the channels you want to publish to.

Here’s how you can retrieve a list of all your publications:

{
  publications(first: 10) {
    edges {
      node {
        id
        name
        app {
          id
          title
        }
      }
    }
  }
}

This will return a list of publications, each with an ID, name, and associated app (which represents the sales channel).

You can then use the Publication IDs in your productPublications array:

"productPublications": [
  {
    "publicationId": "gid://shopify/Publication/123"
  },
  {
    "publicationId": "gid://shopify/Publication/234"
  }
]

Please try this and let us know if you still encounter any issues.

1 Like

Thank you Liam. This solved my issue using the publications.

A quick follow-up question for you, I was wondering if there’s a way to send just the sales channels? Each app will have a publication, and in some cases the names of the publications don’t match the name of the sales channel.

I wanted to try the publications query but I get the following error message: “Access denied for publications field. Required access: read_publications access scope”. Looking at the access scopes of my custom app, I noticed that I already enabled this access scope. Any idea how to fix this?

I would double check you are using the access key that has that permission. I can’t think of any reason that would fail without it being related to the key not having permission.