【发布时间】:2021-05-18 16:31:24
【问题描述】:
我正在发出 POST 请求以创建 Royal Mail Click and Drop 订单:
$response = Http::withHeaders([
'Content-Type' => 'application/json',
'Authorization' => 'Bearer secret-123'
])->post('https://api.parcel.royalmail.com/api/v1/orders/', [
'items' => [
'recipient' => [
'address' => [
"fullName" => 'Tom',
"companyName" => "Test",
"addressLine1" => "150",
"addressLine2" => "Valley Close",
"addressLine3" => "Elmdom",
"city" => "Birmingham",
"county" => "West Midlands",
"postcode" => "B12 2YT",
"countryCode" => "GB"
],
"emailAddress" => "test@test.com"
],
"billing" => [
"address" => [
"fullName" => 'Tom',
"companyName" => "Test",
"addressLine1" => "150",
"addressLine2" => "Valley Close",
"addressLine3" => "Elmdom",
"city" => "Birmingham",
"county" => "West Midlands",
"postcode" => "B12 2YT",
"countryCode" => "GB"
],
"phoneNumber" => "42425 5252552",
"emailAddress" => "test@test.com"
],
"orderDate" => "2021-05-18T16:39:01Z",
"subtotal" => 0,
"shippingCostCharged" => 0,
"total" => 0,
]
])->json();
dd($response);
但不断得到
'反序列化对象时出现意外标记:PropertyName。路径“items.recipient”,第 1 行,位置 22。未能反序列化以下订单请求'
我不断收到所有必填字段的相同错误...
API 文档没有提供太多细节https://api.parcel.royalmail.com/。相同的有效负载适用于 Insomnia。我正在使用 Laravel Http 客户端。
【问题讨论】:
-
它不喜欢你的地址。您必须发布您发送的内容,以便我们了解原因。
-
抱歉,我已经用 POST 请求有效负载的完整示例更新了原始帖子。