Request is not well-formed, syntactically incorrect, or violates schema.

knutsford
Contributor
Contributor

{"intent":"CAPTURE","purchase_units":{"amount":{"currency_code":"GBP","value":"3.5"}}}

 

 

is myjson

 

 

It is returning 

 

 

{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"71ab5a6cf35d3","details":[{"field":"/purchase_units","location":"body","issue":"MALFORMED_REQUEST_JSON","description":"The request JSON is not well formed."}],"links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-MALFORMED_REQUEST_JSON","rel":"information_link","encType":"application/json"}]}

 

This is my create function

 

function create_order($access_token, $Total, $Currency)
{
$ch = false;
$http_header = array
(
"Content-Type: application/json",
"Authorization: Bearer " . $access_token,
);

$post_fields = array ("intent" => "CAPTURE",
"purchase_units" =>
array (
"amount" =>
array (
"currency_code" => $Currency,
"value" => $Total
)
)
);
$jsonData = json_encode($post_fields);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api-m.sandbox.paypal.com/v2/checkout/orders");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $http_header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
$result = curl_exec($ch);
$json = json_encode($result);
print_r($jsonData);
echo $result;
curl_close($ch);
return $json;
}

 

Login to Me Too
1 ACCEPTED SOLUTION

Accepted Solutions
Solved

knutsford
Contributor
Contributor

Thanks so I gather  - oops. A case of seeing what you think is on the screen and not what is actually there. Thanks

View solution in original post

Login to Me Too
2 REPLIES 2

MTS_Chiranjeevi
Moderator
Moderator

Good day @knutsford,

 

Thank you for posting to the PayPal community.

 

Yes, this is an issue with your Create Order API request JSON which is not well formed. 

 

"purchase_units": field is not well formed and it is an Array of Objects. 

 

https://developer.paypal.com/docs/api/orders/v2/#orders_create!path=purchase_units&t=request 


I see that your passing "{ }" instead of "[ ]" for the "purchase_units" in Create Order API request JSON which is the reason why your facing this error. 

 

Please refer the below sample :

 

  "intent": "CAPTURE",
  "purchase_units": [
    {
      "reference_id": "**************",
      "amount": {
        "currency_code": "USD",
        "value": "100.00"
      }
    }
  ],

 

https://developer.paypal.com/docs/api/orders/v2/#orders_create 

 

Sincerely,

Chiranjeevi

PayPal/Braintree MTS

 

If this post or any other was helpful, please enrich the community by giving kudos or accepting it as a solution.

Login to Me Too
Solved

knutsford
Contributor
Contributor

Thanks so I gather  - oops. A case of seeing what you think is on the screen and not what is actually there. Thanks

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.