Quickbooks PHP SDK 采购订单缺少参数错误

Quickbooks PHP SDK purchase orders missing param error

我正在尝试使用 Quickbooks PHP SDK 创建采购订单并不断收到 invalid/missing 参数错误或 ID 可能错误。

我的参数基于 Quickbooks API Explorer。在采购订单的 'Create' 演示下,有一个选项可以生成一些默认值 json/xml。我以为这会给我所需的最低参数。

所以在我的代码中,我使用这些参数创建了一个采购订单数组并组成了值。但无法找出错误或遗漏的地方。

我看到的 PHP QuickBooks SDK 采购订单的少数样本使用的是 Oauth 1.0,因此我的应用程序使用的是 Oauth 2.0,因此不值得花时间去玩它们

错误

The Status code is: 400 The Helper message is: Invalid auth/bad request strong text(got a 400, expected HTTP/1.1 20X or a redirect) The Response message is: Invalid Reference IdInvalid Reference Id : Something you're trying to use has been made inactive. Check the fields with accounts, customers, items, vendors or employees.

示例 JSON 来自 QUICKBOOKS API Explorer(来自 App 沙箱的数据)

{
    "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 参数为基础

  • 转到您APP的API浏览器和select采购订单https://developer.intuit.com/v2/apiexplorer?apiname=V3QBO#?id=PurchaseOrder
  • 在页面底部找到 'Query' 浏览器。
  • 在查询字段中输入 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);
}