I am using curl to create the customer using shopify Admin Rest Api,
Below is my code.
$payload = json_encode([
"customer" => [
"first_name" => "Jagdish",
"last_name" => "Joshi",
"email" => "jagdishgentraf@gmail.com",
"verified_email" => true,
"send_email_welcome" => false
]
]);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $payload, // Use $payload instead of manually constructing the string
CURLOPT_HTTPHEADER => array(
'X-Shopify-Access-Token: xxxxxxxxxxxxxxxxxxxxxxxx',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
//echo "success";
$customerData = json_decode($response, true);
if (isset($customerData['customer']['id'])) {
echo $customerData['customer']['id'];
} else {
// Print the full response to see any additional error details
echo "Error in Response: " . $response;
}
}
return 1;
But I am getting following error:
{"errors":{"customer":"Required parameter missing or invalid"}}
Please guide us to resolve the above problem.