collection Add Productsmutation
Requires write
access scope. Also: The store must not be on the Starter or Retail plans and user must have a permission to add products to a collection.
Adds products to a collection.
Arguments
The ID of the collection that's being updated. This can't be a smart collection.
The IDs of the products that are being added to the collection. If any of the products is already present in the input collection, then an error is raised and no products are added.
CollectionAddProductsPayload returns
The updated collection. Returns
null
if an error is raised.The list of errors that occurred from executing the mutation.
Code examples for MUTATION: collectionAddProducts
Query Reference for MUTATION: collectionAddProducts
"mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n # Collection fields\n }\n userErrors {\n field\n message\n }\n }\n}"
Input Reference for MUTATION: collectionAddProducts
"{\n \"id\": \"gid://shopify/<objectName>/10079785100\",\n \"productIds\": [\n \"gid://shopify/<objectName>/10079785100\"\n ]\n}"
Schema Reference for MUTATION: collectionAddProducts
""
Display Examples for MUTATION: collectionAddProducts
[ { "example": { "type_name": "collectionaddproducts", "title": "Add a product to a collection that doesn't exist", "description": "If the input collection doesn't exist, then the mutation returns an error.\n", "query_string": "mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n}", "variables": { "id": "gid://shopify/Collection/-1", "productIds": [ "gid://shopify/Product/108828309" ] }, "response": { "data": { "collectionAddProducts": { "collection": null, "userErrors": [ { "field": [ "id" ], "message": "Collection does not exist" } ] } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/merchandising/test/unit/graph_api/admin/mutations/collection_add_products_test.rb", "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) { collectionAddProducts(id: $id, productIds: $productIds) { collection { id title products(first: 10) { nodes { id title } } } userErrors { field message } } }\",\n \"variables\": {\n \"id\": \"gid://shopify/Collection/-1\",\n \"productIds\": [\n \"gid://shopify/Product/108828309\"\n ]\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"id\": \"gid://shopify/Collection/-1\",\n \"productIds\": [\n \"gid://shopify/Product/108828309\"\n ]\n },\n },\n);\n\nconst data = await response.json();\n", "ruby_example": "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"id\": \"gid://shopify/Collection/-1\",\n \"productIds\": [\"gid://shopify/Product/108828309\"]\n}\n\nresponse = client.query(query: query, variables: variables)\n", "node_example": "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"id\": \"gid://shopify/Collection/-1\",\n \"productIds\": [\n \"gid://shopify/Product/108828309\"\n ]\n },\n },\n});\n", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY;\n\n$variables = [\n \"id\" => \"gid://shopify/Collection/-1\",\n \"productIds\" => [\"gid://shopify/Product/108828309\"],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "id", "description": "The ID of the collection that's being updated. This can't be a smart collection.", "type": { "kind": "SCALAR", "name": "ID", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "ID!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "id", "argValue": " \"gid://shopify/Collection/-1\"", "typeKind": "MUTATION" }, { "arg": { "name": "productIds", "description": "The IDs of the products that are being added to the collection.\nIf any of the products is already present in the input collection,\nthen an error is raised and no products are added.", "type": { "kind": "SCALAR", "name": "ID", "list": true, "non_null": true }, "defaultValue": null, "typeSignature": "[ID!]!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "productIds", "argValue": " [\"gid://shopify/Product/108828309\"]", "typeKind": "MUTATION" } ] }, { "example": { "type_name": "collectionaddproducts", "title": "Add a product to a smart collection", "description": "Products can't be manually added to a smart collection, so the mutation returns an error.\n", "query_string": "mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n}", "variables": { "id": "gid://shopify/Collection/142458073", "productIds": [ "gid://shopify/Product/910489600" ] }, "response": { "data": { "collectionAddProducts": { "collection": null, "userErrors": [ { "field": [ "id" ], "message": "Can't manually add products to a smart collection" } ] } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/merchandising/test/unit/graph_api/admin/mutations/collection_add_products_test.rb", "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) { collectionAddProducts(id: $id, productIds: $productIds) { collection { id title products(first: 10) { nodes { id title } } } userErrors { field message } } }\",\n \"variables\": {\n \"id\": \"gid://shopify/Collection/142458073\",\n \"productIds\": [\n \"gid://shopify/Product/910489600\"\n ]\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"id\": \"gid://shopify/Collection/142458073\",\n \"productIds\": [\n \"gid://shopify/Product/910489600\"\n ]\n },\n },\n);\n\nconst data = await response.json();\n", "ruby_example": "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"id\": \"gid://shopify/Collection/142458073\",\n \"productIds\": [\"gid://shopify/Product/910489600\"]\n}\n\nresponse = client.query(query: query, variables: variables)\n", "node_example": "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"id\": \"gid://shopify/Collection/142458073\",\n \"productIds\": [\n \"gid://shopify/Product/910489600\"\n ]\n },\n },\n});\n", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY;\n\n$variables = [\n \"id\" => \"gid://shopify/Collection/142458073\",\n \"productIds\" => [\"gid://shopify/Product/910489600\"],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "id", "description": "The ID of the collection that's being updated. This can't be a smart collection.", "type": { "kind": "SCALAR", "name": "ID", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "ID!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "id", "argValue": " \"gid://shopify/Collection/142458073\"", "typeKind": "MUTATION" }, { "arg": { "name": "productIds", "description": "The IDs of the products that are being added to the collection.\nIf any of the products is already present in the input collection,\nthen an error is raised and no products are added.", "type": { "kind": "SCALAR", "name": "ID", "list": true, "non_null": true }, "defaultValue": null, "typeSignature": "[ID!]!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "productIds", "argValue": " [\"gid://shopify/Product/910489600\"]", "typeKind": "MUTATION" } ] }, { "example": { "type_name": "collectionaddproducts", "title": "Add products that already belong to the specified collection", "description": "An error is returned and no products are added if any of the input products already belong to the input collection.\n", "query_string": "mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n}", "variables": { "id": "gid://shopify/Collection/1007901140", "productIds": [ "gid://shopify/Product/108828309", "gid://shopify/Product/632910392", "gid://shopify/Product/20995642" ] }, "response": { "data": { "collectionAddProducts": { "collection": null, "userErrors": [ { "field": [ "productIds" ], "message": "Error adding gid://shopify/Product/108828309,gid://shopify/Product/20995642 to collection" } ] } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/merchandising/test/unit/graph_api/admin/mutations/collection_add_products_test.rb", "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) { collectionAddProducts(id: $id, productIds: $productIds) { collection { id title products(first: 10) { nodes { id title } } } userErrors { field message } } }\",\n \"variables\": {\n \"id\": \"gid://shopify/Collection/1007901140\",\n \"productIds\": [\n \"gid://shopify/Product/108828309\",\n \"gid://shopify/Product/632910392\",\n \"gid://shopify/Product/20995642\"\n ]\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"id\": \"gid://shopify/Collection/1007901140\",\n \"productIds\": [\n \"gid://shopify/Product/108828309\",\n \"gid://shopify/Product/632910392\",\n \"gid://shopify/Product/20995642\"\n ]\n },\n },\n);\n\nconst data = await response.json();\n", "ruby_example": "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"id\": \"gid://shopify/Collection/1007901140\",\n \"productIds\": [\"gid://shopify/Product/108828309\", \"gid://shopify/Product/632910392\", \"gid://shopify/Product/20995642\"]\n}\n\nresponse = client.query(query: query, variables: variables)\n", "node_example": "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"id\": \"gid://shopify/Collection/1007901140\",\n \"productIds\": [\n \"gid://shopify/Product/108828309\",\n \"gid://shopify/Product/632910392\",\n \"gid://shopify/Product/20995642\"\n ]\n },\n },\n});\n", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY;\n\n$variables = [\n \"id\" => \"gid://shopify/Collection/1007901140\",\n \"productIds\" => [\"gid://shopify/Product/108828309\", \"gid://shopify/Product/632910392\", \"gid://shopify/Product/20995642\"],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "id", "description": "The ID of the collection that's being updated. This can't be a smart collection.", "type": { "kind": "SCALAR", "name": "ID", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "ID!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "id", "argValue": " \"gid://shopify/Collection/1007901140\"", "typeKind": "MUTATION" }, { "arg": { "name": "productIds", "description": "The IDs of the products that are being added to the collection.\nIf any of the products is already present in the input collection,\nthen an error is raised and no products are added.", "type": { "kind": "SCALAR", "name": "ID", "list": true, "non_null": true }, "defaultValue": null, "typeSignature": "[ID!]!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "productIds", "argValue": " [\"gid://shopify/Product/108828309\",\"gid://shopify/Product/632910392\",\"gid://shopify/Product/20995642\"]", "typeKind": "MUTATION" } ] }, { "example": { "type_name": "collectionaddproducts", "title": "Add products that don't exist to an existing collection", "description": "Products that don't exist are ignored.\n", "query_string": "mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n}", "variables": { "id": "gid://shopify/Collection/636030761", "productIds": [ "gid://shopify/Product/-1", "gid://shopify/Product/108828309", "gid://shopify/Product/-2" ] }, "response": { "data": { "collectionAddProducts": { "collection": { "id": "gid://shopify/Collection/636030761", "title": "Unpublished items", "products": { "nodes": [ { "id": "gid://shopify/Product/108828309", "title": "Draft" } ] } }, "userErrors": [] } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/merchandising/test/unit/graph_api/admin/mutations/collection_add_products_test.rb", "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) { collectionAddProducts(id: $id, productIds: $productIds) { collection { id title products(first: 10) { nodes { id title } } } userErrors { field message } } }\",\n \"variables\": {\n \"id\": \"gid://shopify/Collection/636030761\",\n \"productIds\": [\n \"gid://shopify/Product/-1\",\n \"gid://shopify/Product/108828309\",\n \"gid://shopify/Product/-2\"\n ]\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"id\": \"gid://shopify/Collection/636030761\",\n \"productIds\": [\n \"gid://shopify/Product/-1\",\n \"gid://shopify/Product/108828309\",\n \"gid://shopify/Product/-2\"\n ]\n },\n },\n);\n\nconst data = await response.json();\n", "ruby_example": "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"id\": \"gid://shopify/Collection/636030761\",\n \"productIds\": [\"gid://shopify/Product/-1\", \"gid://shopify/Product/108828309\", \"gid://shopify/Product/-2\"]\n}\n\nresponse = client.query(query: query, variables: variables)\n", "node_example": "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"id\": \"gid://shopify/Collection/636030761\",\n \"productIds\": [\n \"gid://shopify/Product/-1\",\n \"gid://shopify/Product/108828309\",\n \"gid://shopify/Product/-2\"\n ]\n },\n },\n});\n", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY;\n\n$variables = [\n \"id\" => \"gid://shopify/Collection/636030761\",\n \"productIds\" => [\"gid://shopify/Product/-1\", \"gid://shopify/Product/108828309\", \"gid://shopify/Product/-2\"],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "id", "description": "The ID of the collection that's being updated. This can't be a smart collection.", "type": { "kind": "SCALAR", "name": "ID", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "ID!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "id", "argValue": " \"gid://shopify/Collection/636030761\"", "typeKind": "MUTATION" }, { "arg": { "name": "productIds", "description": "The IDs of the products that are being added to the collection.\nIf any of the products is already present in the input collection,\nthen an error is raised and no products are added.", "type": { "kind": "SCALAR", "name": "ID", "list": true, "non_null": true }, "defaultValue": null, "typeSignature": "[ID!]!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "productIds", "argValue": " [\"gid://shopify/Product/-1\",\"gid://shopify/Product/108828309\",\"gid://shopify/Product/-2\"]", "typeKind": "MUTATION" } ] }, { "example": { "type_name": "collectionaddproducts", "title": "Add products to an existing collection", "description": "Add two products with specified IDs to the collection.\n", "query_string": "mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n}", "variables": { "id": "gid://shopify/Collection/636030761", "productIds": [ "gid://shopify/Product/121709582", "gid://shopify/Product/108828309" ] }, "response": { "data": { "collectionAddProducts": { "collection": { "id": "gid://shopify/Collection/636030761", "title": "Unpublished items", "products": { "nodes": [ { "id": "gid://shopify/Product/121709582", "title": "Boots" }, { "id": "gid://shopify/Product/108828309", "title": "Draft" } ] } }, "userErrors": [] } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/merchandising/test/unit/graph_api/admin/mutations/collection_add_products_test.rb", "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) { collectionAddProducts(id: $id, productIds: $productIds) { collection { id title products(first: 10) { nodes { id title } } } userErrors { field message } } }\",\n \"variables\": {\n \"id\": \"gid://shopify/Collection/636030761\",\n \"productIds\": [\n \"gid://shopify/Product/121709582\",\n \"gid://shopify/Product/108828309\"\n ]\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"id\": \"gid://shopify/Collection/636030761\",\n \"productIds\": [\n \"gid://shopify/Product/121709582\",\n \"gid://shopify/Product/108828309\"\n ]\n },\n },\n);\n\nconst data = await response.json();\n", "ruby_example": "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"id\": \"gid://shopify/Collection/636030761\",\n \"productIds\": [\"gid://shopify/Product/121709582\", \"gid://shopify/Product/108828309\"]\n}\n\nresponse = client.query(query: query, variables: variables)\n", "node_example": "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"id\": \"gid://shopify/Collection/636030761\",\n \"productIds\": [\n \"gid://shopify/Product/121709582\",\n \"gid://shopify/Product/108828309\"\n ]\n },\n },\n});\n", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY;\n\n$variables = [\n \"id\" => \"gid://shopify/Collection/636030761\",\n \"productIds\" => [\"gid://shopify/Product/121709582\", \"gid://shopify/Product/108828309\"],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "id", "description": "The ID of the collection that's being updated. This can't be a smart collection.", "type": { "kind": "SCALAR", "name": "ID", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "ID!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "id", "argValue": " \"gid://shopify/Collection/636030761\"", "typeKind": "MUTATION" }, { "arg": { "name": "productIds", "description": "The IDs of the products that are being added to the collection.\nIf any of the products is already present in the input collection,\nthen an error is raised and no products are added.", "type": { "kind": "SCALAR", "name": "ID", "list": true, "non_null": true }, "defaultValue": null, "typeSignature": "[ID!]!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "productIds", "argValue": " [\"gid://shopify/Product/121709582\",\"gid://shopify/Product/108828309\"]", "typeKind": "MUTATION" } ] }, { "example": { "type_name": "collectionaddproducts", "title": "Add products to collections will fail when CollectionsAccess returns false", "description": "CollectionAddProducts mutation will fail for starter plan shops\n", "query_string": "mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n}", "variables": { "id": "gid://shopify/Collection/636030761", "productIds": [ "gid://shopify/Product/121709582", "gid://shopify/Product/108828309" ] }, "response": { "errors": [ { "message": "Access denied for collectionAddProducts field. Required access: `write_products` access scope. Also: The store must not be on the Starter or Retail plans and user must have a permission to add products to a collection.", "locations": [ { "line": 2, "column": 3 } ], "path": [ "collectionAddProducts" ], "extensions": { "code": "ACCESS_DENIED", "documentation": "https://shopify.dev/api/usage/access-scopes", "requiredAccess": "`write_products` access scope. Also: The store must not be on the Starter or Retail plans and user must have a permission to add products to a collection." } } ], "data": { "collectionAddProducts": null } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/merchandising/test/unit/graph_api/admin/mutations/collection_add_products_test.rb", "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) { collectionAddProducts(id: $id, productIds: $productIds) { collection { id title products(first: 10) { nodes { id title } } } userErrors { field message } } }\",\n \"variables\": {\n \"id\": \"gid://shopify/Collection/636030761\",\n \"productIds\": [\n \"gid://shopify/Product/121709582\",\n \"gid://shopify/Product/108828309\"\n ]\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n {\n variables: {\n \"id\": \"gid://shopify/Collection/636030761\",\n \"productIds\": [\n \"gid://shopify/Product/121709582\",\n \"gid://shopify/Product/108828309\"\n ]\n },\n },\n);\n\nconst data = await response.json();\n", "ruby_example": "session = ShopifyAPI::Auth::Session.new(\n shop: \"your-development-store.myshopify.com\",\n access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n session: session\n)\n\nquery = <<~QUERY\n mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY\n\nvariables = {\n \"id\": \"gid://shopify/Collection/636030761\",\n \"productIds\": [\"gid://shopify/Product/121709582\", \"gid://shopify/Product/108828309\"]\n}\n\nresponse = client.query(query: query, variables: variables)\n", "node_example": "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }`,\n \"variables\": {\n \"id\": \"gid://shopify/Collection/636030761\",\n \"productIds\": [\n \"gid://shopify/Product/121709582\",\n \"gid://shopify/Product/108828309\"\n ]\n },\n },\n});\n", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation collectionAddProducts($id: ID!, $productIds: [ID!]!) {\n collectionAddProducts(id: $id, productIds: $productIds) {\n collection {\n id\n title\n products(first: 10) {\n nodes {\n id\n title\n }\n }\n }\n userErrors {\n field\n message\n }\n }\n }\nQUERY;\n\n$variables = [\n \"id\" => \"gid://shopify/Collection/636030761\",\n \"productIds\" => [\"gid://shopify/Product/121709582\", \"gid://shopify/Product/108828309\"],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "id", "description": "The ID of the collection that's being updated. This can't be a smart collection.", "type": { "kind": "SCALAR", "name": "ID", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "ID!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "id", "argValue": " \"gid://shopify/Collection/636030761\"", "typeKind": "MUTATION" }, { "arg": { "name": "productIds", "description": "The IDs of the products that are being added to the collection.\nIf any of the products is already present in the input collection,\nthen an error is raised and no products are added.", "type": { "kind": "SCALAR", "name": "ID", "list": true, "non_null": true }, "defaultValue": null, "typeSignature": "[ID!]!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "productIds", "argValue": " [\"gid://shopify/Product/121709582\",\"gid://shopify/Product/108828309\"]", "typeKind": "MUTATION" } ] } ]