Fulfillment with PHP error 406

kahmra
Tourist
8 0 1

hi! i have this code

 

 

	private function makePostRequest($url, $postData) {
		$curl = curl_init();

		curl_setopt($curl, CURLOPT_URL, $url);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($curl, CURLOPT_POST, true);
		curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($postData)); // Codifica a JSON aquí
		curl_setopt($curl, CURLOPT_HTTPHEADER, [
			'Content-Type: application/json',
			'Accept: application/json', // Asegúrate de aceptar JSON
			'Authorization: Basic ' . base64_encode("{$this->apiKey}:{$this->password}")
		]);

		$response = curl_exec($curl);
		$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
		$error = curl_error($curl);
		curl_close($curl);

		return [
			'response' => json_decode($response, true),
			'http_code' => $httpCode,
			'error' => $error
		];
	}

 

 

and i trying to fulfill a order , for that i have this function

 

 

public function fulfillOrder($orderId, $location_id, $fullfilment_order_id, $trackingNumber, $trackingUrl) {
		$apiUrl = "{$this->start_url}/orders/{$orderId}/fulfillments.json";
		
		$postData = [
			'fulfillment' => [
				'line_items_by_fulfillment_order' => [
					[
						'fulfillment_order_id' => $fullfilment_order_id
					]
				],
				'notify_customer' => true,
				'tracking_info' => [
					'number' => $trackingNumber,
					'company' => 'Other',
					'url' => $trackingUrl,
				],
				'location_id' => $location_id
			]
		];
		
		echo $apiUrl;
		$response = $this->makePostRequest($apiUrl, $postData);
		
		echo "<pre>";
		print_r($postData);
		print_r($response);
		echo "</pre>";
		if ($response['http_code'] == 201) {
			return $response['response'];
		} else {
			return [
				'error' => $response['error'],
				'http_code' => $response['http_code'],
				'response' => $response['response']
			];
		}
	}

 

 

but i got this error:

 

 

Array
(
    [response] => 
    [http_code] => 406
    [error] => 
)

 

 

 

anyone can helpme pls

Reply 1 (1)

Atanu_Sarkar
Shopify Partner
10 3 3

Hi @kahmra ,

You can try changing this line

 

 

curl_setopt($curl, CURLOPT_HTTPHEADER, [
   'Content-Type: application/json',
   'Accept: application/json', // Asegúrate de aceptar JSON
   'Authorization: Basic ' . base64_encode("{$this->apiKey}:{$this->password}")
]);

 

 

to this

 

 

curl_setopt($curl, CURLOPT_HTTPHEADER, [
   'Content-Type: application/json',
   'X-Shopify-Access-Token: ' . "{$this->password}"
]);

 

 

Let me know if it works.