How to create a collection Available online GraphQl

Solved
waliby
Shopify Partner
8 0 1

I've tried the mutation to create a collection, It seems there is no argument to make the new collection available online, I saw that with the REST API, we can use the arg "published": true

 

Can you please explain me the way to do this with GraphQl ? 

 

0 Likes
Zameer
Shopify Staff
Shopify Staff
295 32 76

This is an accepted solution.

Hey Waliby,

 

This is definitely also possible in GraphQL, it just requires a separate mutation.

 

First, you create the collection as you mentioned, using the collectionCreate mutation.

 

Next, you get the publication id where you want to publish the collection, in your case the Online Store. This can be done using the publications QueryRoot:

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

 

Lastly, you publish the collection using the publishablePublish mutation (not the greatest name):

mutation publishablePublish($id: ID!, $input: [PublicationInput!]!) {
  publishablePublish(id: $id, input: $input) {
    userErrors {
      field
      message
    }
  }
}

 

Here you have to provide an input variable with both the id of the collection you want to publish as the "id" key and then the id of the publication (Online Store) as "publicationId" key, both base64 encoded:

{
  "id": "{collection_id_base_64}",
  "input": [
    {"publicationId": "publication_id_base_64"}
  ]
}

This should allow you to create a collection and publish it appropriately in the Online Store. Let me know if you run into any issues!

waliby
Shopify Partner
8 0 1

Thank you so much, it works perfectly.

0 Likes
Tejas-Ambalia
Tourist
4 0 1

I am not able to get the collections list. I am getting the below error. I am using a private app on the Shopify Plus store. but, I am not seeing a scope which name is read_publications into the admin area. how can I give this permission to my private app?

 

Access denied for publications field. Required access: `read_publications` access scope.  This scope is currently available only to private apps installed on Shopify Plus stores.

 

0 Likes
waliby
Shopify Partner
8 0 1

Have you tried to pull a list of collection from the GraphQl app ?
If it works with a simple structure like:

query{
				collections(first:1){
					edges{
						cursor,
						node{
							legacyResourceId,
              title
						}
					}
  }
  }

read_products should be enough just to get a list.

0 Likes