PHP Post Returns Invalid JSON on clean install
-
Hi Sebastien,
With a clean install of Co Cart and a test product added to woo commerce I have tried to use your documented example to simply add a product.
The response I get is:
{“code”:”rest_invalid_json”,”message”:”Invalid JSON body passed.”,”data”:{“status”:400,”json_error_code”:4,”json_error_message”:”Syntax error”}}Any ideas?
It appears the get requests are working correctly but there is a problem with POST, I have tried to $json_encode the $args array to test but I then get response of Product Id must be specified??Code being called below (as per your documentation).
Many Thanks
Chris
<?php
$curl = curl_init();$args = array(
‘product_id’ => “203”,
‘quantity’ => 1
);curl_setopt_array( $curl, array(
CURLOPT_URL => “https://mydomain.com/wp-json/cocart/v1/add-item”,
CURLOPT_CUSTOMREQUEST => “POST”,
CURLOPT_POSTFIELDS => $args,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => array(
‘Accept: application/json’,
‘Content-Type: application/json’,
‘User-Agent: CoCart API/v1’,
)
) );$response = curl_exec($curl);
curl_close($curl);
echo $response;
- The topic ‘PHP Post Returns Invalid JSON on clean install’ is closed to new replies.