我正试图使用Quickbooks PHP SDK创建采购订单,但不断收到无效/丢失的参数错误或可能错误的ID。
我的参数基于Quickbooks API资源管理器。在采购订单的"创建"演示中,可以选择生成一些默认的json/xml。我以为这会给我所需的最低参数。
因此,在我的代码中,我用这些Params创建了一个Purchase Order数组,并组成了值。但无法找出错误或缺失的地方。
我看到的为数不多的PHP QuickBooks SDK采购订单样本使用的是Oauth 1.0,所以玩它们不值得我花时间,因为我的应用程序使用的是Oauth 2.0
错误
状态代码为:400帮助程序消息为:无效身份验证/错误请求强文本(得到400,应为HTTP/1.1 20X或重定向)响应消息为:Invalid Reference IdInvalid ReferenceId:您试图使用的某些内容已被设为非活动状态。检查帐户、客户、项目、供应商或员工的字段。
来自QUICKBOOKS API资源管理器的样本JSON(来自应用程序沙箱的数据)
{
"Line": [{
"Id": "1",
"Amount": 25.0,
"DetailType": "ItemBasedExpenseLineDetail",
"ItemBasedExpenseLineDetail": {
"CustomerRef": {
"value": "3",
"name": "Cool Cars"
},
"BillableStatus": "NotBillable",
"ItemRef": {
"value": "38",
"name": "Garden Supplies"
},
"UnitPrice": 25,
"Qty": 1,
"TaxCodeRef": {
"value": "NON"
}
}
}],
"VendorRef": {
"value": "41",
"name": "Hicks Hardware"
},
"APAccountRef": {
"value": "33",
"name": "Accounts Payable (A/P)"
},
"TotalAmt": 25.0
}
Quickbooks.php(仅重要部分)
$purchaseOrder = PurchaseOrder::create([
"Line" =>[
[
"Id" =>"0",
"Amount" => 25.0,
"DetailType" => "ItemBasedExpenseLineDetail",
"ItemBasedExpenseLineDetail"=>
[
"CustomerRef"=>
[
"value"=>"3",
"name"=>"Cool Cars"
],
"BillableStatus"=> "NotBillable",
"ItemRef"=>
[
"value"=> "38",
"name"=> "Garden Supplies"
],
"UnitPrice"=> "25",
"Qty"=>"1",
"TaxCodeRef"=>
[
"value"=> "NON",
]
]
]
],
"VendorRef"=>
[
"value"=>"41",
"name"=>"Hicks Hardware"
],
"APAccountRef"=>
[
"value"=>"33",
"name"=>"Accounts Payable (A/P)"
],
"TotalAmt"=> 25.0
]);
$resultingpurchaseOrder = $dataService->Add($purchaseOrder);
$error = $dataService->getLastError();
if ($error != null) {
echo "The Status code is: " . $error->getHttpStatusCode() . "n";
echo "The Helper message is: " . $error->getOAuthHelperError() . "n";
echo "The Response message is: " . $error->getResponseBody() . "n";
} else {
var_dump($resultingpurchaseOrder);
}
花了一段时间才弄清楚,但以下是我为在沙箱中创建成功的示例采购订单所做的工作。
找到好样本Json/XML的提示,以使PO参数远离
- 进入应用程序的API资源管理器,选择采购订单https://developer.intuit.com/v2/apiexplorer?apiname=V3QBO#?id=PurchaseOrder
- 在页面底部找到"查询">资源管理器
- 在查询字段中输入select*from PurchaseOrder
- 返回的大部分xml/json可以用于您的PO参数
- 我删除了一些东西,包括ID(我相信这是QB自动生成的)
- 请参阅下面的最后一个代码示例,作为需要或不需要参数的参考
这只是一个测试创建对我有效的PO的示例,发布以防对其他人有帮助。
创建采购订单示例
$dataService = DataService::Configure(array(
'auth_mode' => 'oauth2',
'ClientID' => "",
'ClientSecret' => "",
'accessTokenKey' => "",
'refreshTokenKey' => '',
'QBORealmID' => "",
'baseUrl' => "https://sandbox-quickbooks.api.intuit.com"
));
$OAuth2LoginHelper = $dataService->getOAuth2LoginHelper();
$accessToken = $OAuth2LoginHelper->refreshToken();
$error = $OAuth2LoginHelper->getLastError();
if ($error != null) {
echo "The Status code is: " . $error->getHttpStatusCode() . "n";
echo "The Helper message is: " . $error->getOAuthHelperError() . "n";
echo "The Response message is: " . $error->getResponseBody() . "n";
return;
}
$dataService->updateOAuth2Token($accessToken);
$dataService->setLogLocation("/home/lindsay/Desktop/log");
$purchaseOrder = PurchaseOrder::create([
"ShipAddr" => [
"Id"=> "96",
"Line1"=> "Sandbox Company_US_1",
"Line2"=> "123 Sierra Way",
"Line3"=> "San Pablo, CA 87999"
],
"Line" =>[
[
"Id" =>"1",
"Description" => "This is the purchasing description.",
"Amount" => 5.0,
"DetailType" => "ItemBasedExpenseLineDetail",
"ItemBasedExpenseLineDetail"=>
[
"CustomerRef"=>
[
"value"=>"4",
"name"=>"Diego Rodriguez"
],
"BillableStatus"=> "NotBillable",
"ItemRef"=>
[
"value"=> "19",
"name"=> "T-Shirt"
],
"UnitPrice"=> "5",
"Qty"=>"1",
"TaxCodeRef"=>
[
"value"=> "NON",
]
]
]
],
"VendorRef"=>
[
"value"=>"56",
"name"=>"Bob's Burger Joint"
],
"APAccountRef"=>
[
"value"=>"33",
"name"=>"Accounts Payable (A/P)"
],
"TotalAmt"=> 5.0,
"Memo" => "vendor message test!"
]);
$resultingpurchaseOrder = $dataService->Add($purchaseOrder);
$error = $dataService->getLastError();
if ($error != null) {
echo "The Status code is: " . $error->getHttpStatusCode() . "n";
echo "The Helper message is: " . $error->getOAuthHelperError() . "n";
echo "The Response message is: " . $error->getResponseBody() . "n";
} else {
var_dump($resultingpurchaseOrder);
}