You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

QuickBooks API调用报GuzzleHttp请求含无效或不支持属性错误如何修复

QuickBooks API 400 Bad Request 错误修复方案

报错原文:GuzzleHttp\Exception\ClientException 客户端错误:POST https://sandbox-quickbooks.api.intuit.com//*Private 端点返回400 Bad Request响应:{"Fault":{"Error":[{"Message":"Request has invalid or unsupported property","Detail":"Property Name:Unrecognized field \

该报错的核心原因是请求体中包含QuickBooks创建Customer接口不识别的字段,或字段值不符合接口规范。结合提供的代码,排查和修复步骤如下:

常见问题排查方向

  • 字段值格式错误:BillAddr下的CountrySubDivisionCode要求传对应国家的行政区域编码(比如美国传两位州缩写、中国传省级两位编码),Country要求传两位国家代码,如果传了全称、中文名称或空值,会触发字段不识别错误
  • 字段名拼写错误:确认所有提交的字段名大小写、拼写完全匹配接口要求,当前代码中字段名拼写规则正确,可检查是否存在笔误
  • 特殊字符未转义:如果DisplayName、CompanyName等文本字段包含&、<、>等特殊字符未转义,会导致接口解析字段失败
  • 包含多余字段:请求体中如果有接口不支持的自定义字段,也会触发该报错

调试与修复步骤

  1. 先打印完整请求体,确认实际提交的内容:
if(!$buyer->details->quickbooks_id){
    $postData = [
        'PrimaryEmailAddr' => [
            'Address' => $buyer->email
        ],
        'DisplayName' => $buyer->first_name.' '.$buyer->last_name.' - '.$buyer->details->business_name,
        'PrimaryPhone'=>[
            'FreeFormNumber'=> $buyer->phone
        ],
        'CompanyName'=>$buyer->details->business_name,
        'GivenName'=>$buyer->first_name,
        'FamilyName'=>$buyer->last_name,
        'BillAddr'=> [
            "CountrySubDivisionCode" => $buyer->details->state, 
            "City" => $buyer->details->city, 
            "PostalCode" => $buyer->details->zip, 
            "Line1" => $buyer->details->address,
            "Country" => $buyer->details->country
        ]
    ];
    // 临时打印请求体确认内容,调试完成后删除
    dd(json_encode($postData));
    
    $customer = $http->post(
        // Sandbox API hidden for security reason
        [
            'headers' => [
                'Accept'=> 'application/json',
                'Content-type'=> 'application/json',
                'Authorization'=> 'Bearer '.$oauth['access_token']
            ],
            'body' => json_encode($postData)
        ]
    );
    $customer = json_decode((string)$customer->getBody(), true);
    $buyer->details->quickbooks_id = $customer['Customer']['Id'];
    $buyer->details->save();
}

dd($buyer, $buyer->details, $buyer->details->quickbooks_id);
  1. 最小可用测试:先注释掉PrimaryPhone、BillAddr等非必填字段,只保留DisplayName、PrimaryEmailAddr两个必填字段提交,确认请求可正常返回后,再逐个添加其他字段,快速定位出问题的字段
  2. 字段校验:提交前对所有字段做非空校验和格式校验,确保地址类字段值符合接口规范

内容的提问来源于stack exchange,提问作者Kirit Pendyala

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.08 10:06:03