为JSONString Zoho库存api传递了无效值

问题描述 投票:0回答:1

我正在尝试使用zoho清单api并转换其示例curl代码以在php中使用

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://inventory.zoho.com/api/v1/salesorders");

$vars = array(
    "authtoken" => "",
    "organization_id" => "",
    "JSONString" => '{
        "customer_id": 4815000000044080,
    }'
);

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$vars);  //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$headers = [
    'Authorization: Zoho-authtoken ',
    'Content-Type: application/json;charset=UTF-8',
];

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$server_output = curl_exec ($ch);

echo $server_output;

curl_close ($ch);

在页面上,我得到此回复

{"code":4,"message":"Invalid value passed for JSONString"}

来自文档的原始代码是

$ curl https://inventory.zoho.com/api/v1/salesorders?authtoken=ba4604e8e433g9c892e360d53463oec5&organization_id=10234695
-X POST
-H "Authorization: Zoho-authtoken ba4604e8e433g9c892e360d53463oec5"
-H "Content-Type: application/json;charset=UTF-8"
-d JSONString='{
    "customer_id": 4815000000044080,
}'

我尝试了各种Google搜索,似乎很多人都遇到了同样的问题,目前还没有答案。

我相信我试图以错误的方式添加JSONString

使用curl在php中发送JSONString的正确方法是什么?

php
1个回答
0
投票

以下是c#代码,不会给出“ {” code“:4,” message“:”为JSONString传递了无效值“}”错误。

https://i.stack.imgur.com/vDRRE.png

如果有任何问题,请给我发邮件。 “[email protected]

© www.soinside.com 2019 - 2024. All rights reserved.