【问题标题】:Quickbooks PHP SDK purchase orders missing param errorQuickbooks PHP SDK 采购订单缺少参数错误
【发布时间】:2017-10-31 22:11:28
【问题描述】:

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

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

所以在我的代码中,我使用这些参数创建了一个采购订单数组并组成了值。但无法弄清楚哪里出了问题或遗漏了什么。

我看到的几个 PHP QuickBooks SDK 采购订单示例使用的是 Oauth 1.0,因此我的 APP 使用 Oauth 2.0,因此不值得花时间玩它们

错误

状态码是:400 帮助程序消息是:无效的身份验证/错误请求强文本(得到 400,预期 HTTP/1.1 20X 或重定向)响应消息是:无效的参考 IdInvalid 参考 ID:你的东西尝试使用已被禁用。检查包含客户、客户、项目、供应商或员工的字段。

QUICKBOOKS API Explorer 中的 SAMPLE 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);
    }

【问题讨论】:

    标签: php oauth-2.0 quickbooks-online purchase-order


    【解决方案1】:

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

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

    • 进入你APP的API Explorer,选择Purchase Ordershttps://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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-31
      • 2010-11-30
      • 2014-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多