checkout function which '/admin/api/2021-01/checkouts.json' is always return line_items is empty.

luan1412167
New Member
1 0 0

Hi,

I have created a checkout with  '/admin/api/2021-01/checkouts.json'  endpoint

Here is code 

	public function createACheckout(array $data)
	{
		// $dataPayload = json_encode($data);
		$client = new \GuzzleHttp\Client();
		// $dataPayload = array();
			// "checkout" => array(
			// 	"line_items" => array(
			// 		"variant_id" => 37259923325090,
			// 		"quantity" => 1,
			// 		"product_id" => 5982282285218
			// 	),
			// ));

		$apiRequestUrl = 'https://' . self::SHOPIFY_SHOP_URL . '/admin/api/2021-01/checkouts.json';
		error_log($data['checkout']['line_items']['quantity']);

		try {
			$response = $client->request(
					'POST',
				 	$apiRequestUrl,
					[
					'headers'  => [
						'Content-Type'           => 'application/json',
						'X-Shopify-Access-Token' => self::SHOPIFY_ACCESS_TOKEN],	
					'json' => json_encode($data)
					]
				// 'form_params' =>  json_encode($dataPayload)
					
			);
			$responseBody = (array)json_decode($response->getBody()->getContents());
			error_log($response->getStatusCode());
			if ($response->getStatusCode()) {
				return [
					'success' => true,
					'statusCode' => 200,
					'code' => "",
					'message' => "",
					'data' => $responseBody
				];
			} else {
				return [
					'success' => false,
					'statusCode' => 405,
					'code' => "",
					'message' => "",
					'data' => 'create Checkout fail'
				];
			}
		} catch (BadResponseException $e) {
			$response = $e->getResponse();
			$jsonBody = json_decode($response->getBody());
			return [
				'success' => false,
				'statusCode' => $response->getStatusCode(),
				'code' => "",
				'message' => $jsonBody,
			];
		}
	}

 

Here is data on postman (variant_id and product_id is exist in product)

{
  "checkout": {
    "line_items": 
      {
        "variant_id": 37259821121698,
        "product_id": 5982254235810,
        "quantity": 1
      }
  }
}

 

Here is the response in postman

{
    "success": true,
    "statusCode": 200,
    "code": "",
    "message": "",
    "data": {
        "checkout": {
            "completed_at": null,
            "created_at": "2021-01-29T07:34:56+08:00",
            "currency": "SGD",
            "presentment_currency": "SGD",
            "customer_id": null,
            "customer_locale": "en",
            "device_id": null,
            "discount_code": null,
            "email": null,
            "legal_notice_url": null,
            "location_id": null,
            "name": "#15476030636194",
            "note": "",
            "note_attributes": {},
            "order_id": null,
            "order_status_url": null,
            "order": null,
            "payment_due": "0.00",
            "payment_url": "https://deposit.us.shopifycs.com/sessions",
            "payments": [],
            "phone": null,
            "shopify_payments_account_id": null,
            "privacy_policy_url": null,
            "refund_policy_url": null,
            "requires_shipping": false,
            "reservation_time_left": 0,
            "reservation_time": null,
            "source_identifier": null,
            "source_name": "4673027",
            "source_url": null,
            "subscription_policy_url": null,
            "subtotal_price": "0.00",
            "shipping_policy_url": null,
            "tax_exempt": false,
            "taxes_included": false,
            "terms_of_sale_url": null,
            "terms_of_service_url": null,
            "token": "53960af171cce4fd63184a0232cbf8ae",
            "total_price": "0.00",
            "total_tax": "0.00",
            "total_tip_received": "0.00",
            "total_line_items_price": "0.00",
            "updated_at": "2021-01-29T07:34:56+08:00",
            "user_id": null,
            "web_url": "https://corsiva-lab-dev.myshopify.com/51929612450/checkouts/53960af171cce4fd63184a0232cbf8ae",
            "line_items": [],
            "gift_cards": [],
            "tax_lines": [],
            "tax_manipulations": [],
            "shipping_line": null,
            "shipping_rate": null,
            "shipping_address": null,
            "credit_card": null,
            "billing_address": null,
            "applied_discount": null
        }
    }
}

 

Please help me solve the issue, it has taken me more 3 days

Thank you

 

0 Likes
Kevin_A
Shopify Staff
Shopify Staff
317 42 55

Hey @luan1412167 

Can you provide us the request ID response headers for any API calls you are making? 

Kevin_A | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me 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

0 Likes