Updating an orders line items gives a 400 error

Hi,

I’m currently trying to update the quantity of an order using the following PHP method. This causes a 400 error. Where am I going wrong? The PHP variables all have values so I figured all the required fields are complete.

I’ve tried to just view an order using similar and it works so it’s correctly identifying the order, it’s just not updating it.

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.veeqo.com/orders/$order_id");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");

curl_setopt($ch, CURLOPT_POSTFIELDS, "{
  \"order\": {
    \"line_items_attributes\": [
      {
        \"sellable_id\": $product_id,
        \"price_per_unit\": $product_price,
        \"quantity\": 10,
      }
    ]
  }
}");

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  "Content-Type: application/json",
  "x-api-key: 123"
));

$response = curl_exec($ch);
curl_close($ch);

var_dump($response);

Hey @robtotm, in the case of a 400 Bad Request you should receive a JSON response containing the errors information (in the error_messages array). Could you please confirm the response body that you receive?

Hi, the errors weren’t very descriptive so it didn’t really point me in the right direction. I figured it out in the end though… I just had to add more detail to the order and create a new channel (as it won’t work with our Woocommerce feed):

  $split_order = [
    "order" => [
      "channel_id" => 65460,
      "customer_id" => $customer_id,
      "deliver_to_id" => $deliver_to_id,
      "delivery_method_id" => $delivery_method_id,
      "payment_attributes" => array(
        "payment_type" => $payment_type
      ),
    ]
  ];