PHP PATCH 产品 PayPal 目录 API 格式错误的请求错误
PHP PATCH Product PayPal Catalog API Malformed request error
我遇到了一个让我抓狂的问题。我正在尝试使用 PayPal 目录 API 更新产品。这是使用以下代码的相当基本的 cURL 调用:
$authorization="Authorization: Bearer ".$authorization;
curl_setopt($ch, CURLOPT_URL, 'https://api.sandbox.paypal.com/v1/catalogs/products/RBW00002');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"op": "replace", "path": "/description", "value": "xxx"}');
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = $authorization;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
$editproduct= json_decode($result);
print_r($editproduct );
echo "<br><br>";
print_r($json);
echo "<br><br>";
unset($headers);
curl_close($ch);
但它不断返回并出现以下错误:
stdClass Object ( [name] => INVALID_REQUEST [message] => Request is not well-formed, syntactically incorrect, or violates schema. [debug_id] => 70cc270a1a2a1 [details] => Array ( [0] => stdClass Object ( [field] => / [location] => body [issue] => MALFORMED_REQUEST_JSON [description] => The request JSON is not well formed. ) ) [links] => Array ( )
有人可以帮忙吗?谢谢!
根据 Update product details 的文档,顶级项目应该是一个带有 []
方括号的数组
'[
{
"op": "replace",
"path": "/description",
"value": "Premium video streaming service"
}
]'
我遇到了一个让我抓狂的问题。我正在尝试使用 PayPal 目录 API 更新产品。这是使用以下代码的相当基本的 cURL 调用:
$authorization="Authorization: Bearer ".$authorization;
curl_setopt($ch, CURLOPT_URL, 'https://api.sandbox.paypal.com/v1/catalogs/products/RBW00002');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"op": "replace", "path": "/description", "value": "xxx"}');
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = $authorization;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
$editproduct= json_decode($result);
print_r($editproduct );
echo "<br><br>";
print_r($json);
echo "<br><br>";
unset($headers);
curl_close($ch);
但它不断返回并出现以下错误:
stdClass Object ( [name] => INVALID_REQUEST [message] => Request is not well-formed, syntactically incorrect, or violates schema. [debug_id] => 70cc270a1a2a1 [details] => Array ( [0] => stdClass Object ( [field] => / [location] => body [issue] => MALFORMED_REQUEST_JSON [description] => The request JSON is not well formed. ) ) [links] => Array ( )
有人可以帮忙吗?谢谢!
根据 Update product details 的文档,顶级项目应该是一个带有 []
方括号的数组
'[
{
"op": "replace",
"path": "/description",
"value": "Premium video streaming service"
}
]'