I want to change fulfilment shipment_status to “delivered” using shopify API
You can use the method below to change the shipment_status
mutation MarkFulfillmentAsDelivered($input: FulfillmentEventInput!) {
fulfillmentEventCreate(input: $input) {
fulfillmentEvent {
id
status
happenedAt
}
userErrors {
field
message
}
}
}
Variables:
{
"input": {
"fulfillmentId": "gid://shopify/Fulfillment/123456789",
"status": "DELIVERED",
"happenedAt": "2023-10-01T12:00:00Z"
}
}
fulfillmentId: The ID of the fulfillment you want to update.
status: Set to “DELIVERED” to mark the shipment as delivered.
happenedAt: The timestamp when the delivery occurred.
This is right code i have tested it’s working fine..
$shop = “test.myshopify.com”;
$access_token = “ssssssssssdfrytyuyuytu”;
$url = “https://$shop/admin/api/2023-01/graphql.json”;
// Get the current timestamp in ISO 8601 format
$happened_at = date(‘c’);
// Replace with actual fulfillment GID (retrieve using an order query if needed)
$fulfillment_id = “gid://shopify/Fulfillment/55557979797”;
// GraphQL Mutation (Now using the correct object structure)
$query = <<<GRAPHQL
mutation {
fulfillmentEventCreate(fulfillmentEvent: {
fulfillmentId: “$fulfillment_id”,
status: DELIVERED,
happenedAt: “$happened_at”
}) {
fulfillmentEvent {
id
status
happenedAt
}
userErrors {
field
message
}
}
}
GRAPHQL;
$data = json_encode([“query” => $query]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
“Content-Type: application/json”,
“Accept: application/json”,
“X-Shopify-Access-Token: $access_token”
]);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);
// Output Response
echo "HTTP Code: " . $http_code . “\n”;
echo "Response: " . print_r(json_decode($response, true), true) . “\n”;
echo "cURL Error: " . ($error ?: “None”) . “\n”;
