A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I am using the Graphql api to do a "bulkOperationRunMutation". But for example, out of 100 products that are sent in the JSONL, some products are not created and it happens randomly. Sometimes, it creates 60 products, sometimes 70 and sometimes 80. It happens randomly for random users.
Have you checked your API response to see if there are any issues or errors with your request?
I receives this response:
"{"errors":false,"response":{"GuzzleHttp\\Psr7\\Response":[]},"status":200,"body":{"Gnikyt\\BasicShopifyAPI\\ResponseAccess":{"data":{"bulkOperationRunMutation":{"bulkOperation":{"id":"gid://shopify/BulkOperation/******************","url":null,"status":"CREATED"},"userErrors":[]}},"
and it clearly shows errors as false and status as CREATED
Hi @haiderdev 👋
We recommend including `userErrors.message` in the underlying mutation. The resulting bulk operation url should include error messages for lines where products were not created successfully.
Hope that helps!
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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
To clarify, `userErrors.message` would be added to the underlying mutation:
mutation {
bulkOperationRunMutation(
mutation: # add to this underlying mutation section as shown below
"mutation ($input: ProductInput!) { productCreate(input: $input) { ... } userErrors { message field } } }",
stagedUploadPath: ...) {
bulkOperation { ... }
userErrors { # not this section
message
field
}
}
}
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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
Oh my, tis the official Shopify Dev Support 😮
This is the same thing that I'm doing.
Could you possibly share some of the code you are using to send this request?
$query = <<<QUERY
mutation {
bulkOperationRunMutation(
mutation: "mutation call(\$input: ProductInput!) { productCreate(input: \$input) { product {id title} userErrors { message field } } }",
stagedUploadPath: "$fileKey") {
bulkOperation {
id
url
status
}
userErrors {
message
field
}
}
}
QUERY;
$resp = $api->graph($query);
I mean it looks correct to me.
function createBulkOperation($shopName, $accessToken, $fileKey) {
$url = "https://{$shopName}.myshopify.com/admin/api/2024-01/graphql.json";
$headers = [
"X-Shopify-Access-Token: {$accessToken}",
'Content-Type: application/json'
];
$query = <<<QUERY
mutation {
bulkOperationRunMutation(
mutation: "mutation call(\$input: ProductInput!) { productCreate(input: \$input) { product {id title} userErrors { message field } } }",
stagedUploadPath: "$fileKey") {
bulkOperation {
id
url
status
}
userErrors {
message
field
}
}
}
QUERY;
$payload = json_encode(['query' => $query]);
$context = stream_context_create([
'http' => [
'method' => 'POST',
'header' => $headers,
'content' => $payload
]
]);
$response = file_get_contents($url, false, $context);
if ($response === FALSE) {
// Handle error
error_log("Error making API request");
return null;
}
return json_decode($response, true);
}
// Usage
$shopName = 'your-shop-name';
$accessToken = 'your-access-token';
$fileKey = 'path_to_your_jsonl_file';
$response = createBulkOperation($shopName, $accessToken, $fileKey);
if ($response) {
// Process the response
print_r($response);
}
You can try something like this to see if you can get those errors to be thrown but without those errors I am unsure. I haven't worked with bulkOperationRunMutation much.
And I've conformed the JSONL file in staged upload, it contains all 100 products. and there are also no errors there.
Haha first rule of development: always assume every line of code has an error or will throw one... 😆
I'm on lunch right now, when I get back I will take a look for you.