0

I'm trying to create purchase orders using Quickbooks PHP SDK and keep getting an invalid/missing param error or possibly wrong ID.

My parameters are based off of the Quickbooks API Explorer. Under the Purchase Order's 'Create' demo, there's an option to generate some default json/xml. I thought this would give me the minimum required params.

So in my code, I have created a Purchase Order array with these Params and made up values. But can't figure out what is wrong or missing.

The few samples of PHP QuickBooks SDK Purchase orders I've seen are using Oauth 1.0, so playing with them was not worth my time since My APP uses Oauth 2.0

ERROR

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.

SAMPLE JSON from QUICKBOOKS API Explorer (data from App sandbox)

{
    "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 (only the important parts)

$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);
    }
4

1 回答 1

0

花了一段时间才弄清楚,但这是我为了在我的沙箱中创建成功的示例采购订单所做的。

提示找到好的示例 Json/XML 以基于 PO 参数

  • 转到您 APP 的 API Explorer 并选择采购订单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);
}
于 2017-10-31T23:24:22.670 回答