集成 godaddy 域时出现意外令牌错误 API

Unexpected token error when integrating godaddy domain API

错误

{"message":"Unexpected token '","body":"{'type':'A','name':'tarunDhiman','data':'166.62.81.221','ttl':3600}"}

代码

$data = "{'type':'A','name':'tarunDhiman','data':'166.62.81.221','ttl':3600}";

$url = "https://api.godaddy.com/v1/domains/{domain}/records";

$headers = array(
    'Content-Type: application/json',
    'Accept : application/json',
    'Authorization : sso-key {key}:{token}' );

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $url);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PATCH');

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$response = curl_exec($curl);

curl_close($curl);
print $response ;
exit;

我认为 header 授权字符串是:

Authorization: sso-key {KEY}:{SECRET}

而不是:

Authorization : sso-key {key}:{token}

并且在 json 字符串中使用双引号而不是单引号:

'{ "type":"A", "name":"tarunDhiman", "data":"166.62.81.221", "ttl":3600 }' 

问题已在 @Slaiv206 的帮助下解决,下面是工作代码。

$data = '[{ "type":"A", "name":"tarunDhiman", "data":"255.255.255.0", "ttl":3600 }]';

$url = "https://api.godaddy.com/v1/domains/{domain}/records";

$headers = array(
 'Content-Type: application/json',
 'Accept : application/json',
 'Authorization : sso-key {key}:{secret}' );

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $url);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PATCH');

curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$response = curl_exec($curl);

curl_close($curl);
print $response ;
exit;