【发布时间】:2021-12-17 04:15:28
【问题描述】:
我正在尝试使用 php cURL 在我的 API 中创建一个新客户端。客户、产品和所有创建的东西都是通过 POST 方法创建的。这是我的代码:
$json='{
"data": {
"type": "customers",
"attributes": {
"tax_registration_number": "5555555550",
"business_name": "Test customer",
"contact_name": "Mr. Test",
"website": "https://www.testurl.pt",
"phone_number": "2299999999",
"mobile_number": "9299999999",
"email": "test@testcustomer.pt",
"observations": "This is only a test",
"internal_observations": "This is good customer",
"not_final_customer": null,
"cashed_vat": null,
"tax_country_region": "PT-MA"
},
"relationships": {
"main_address": {
"data": {
"type": "addresses",
"id": 1
}
},
"addresses": {
"data": [
{
"type": "addresses",
"id": 1
},
{
"type": "addresses",
"id": 2
}
]
}
}
}
}';
print($json);
这里我启动了 cURL,我已经有了令牌和授权:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,($url));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,($json));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/vnd.api+json',
'Accept: application/json',
'Authorization: Bearer ' . $token,
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
var_dump ($response);
$response=json_decode($response,true);
curl_close ($ch);
这是我的回复:
string(329) "{"errors":[{"status":"500 Internal Server Error","code":"JA006","detail":"Erro de sistema JA006: erro interno na base de dados. Por favor contacte o suporte técnico.","meta":{"internal-error":"in JsonapiJson::Value::operator[](ArrayIndex)const: requires arrayValue"}}],"jsonapi":{"version": "1.0","meta":{"libversion":"2.4.1"}}}"
有人可以帮我吗? 谢谢!
【问题讨论】:
-
application/vnd.api+json看起来有点可疑。application/json是普通的 JSON 内容类型(就像在您的接受标头中一样)。除此之外,500 错误实际上是服务器端错误,因此您必须联系 API 的维护人员以了解其崩溃的原因。就我个人而言,我看不出您的代码有任何其他明显错误,但也许其他人会发现一些东西 -
您从 API 收到
JA006 system error: internal database error. Please contact technical support.,因此请联系他们的技术支持