【问题标题】:PHP Laravel Sage One API says invoice lines are required when they are there and not emptyPHP Laravel Sage One API 表示发票行在存在且不为空时是必需的
【发布时间】:2021-10-05 07:09:42
【问题描述】:

我目前正在将应用程序与 Sage One API 集成,但遇到了问题。 API 说发票行可能不是空的,但数据在那里。我做错了什么?

这是我获取订单项的方法:

$lineItems = [];
    foreach ($invoiceItems as $invoiceItem){
      $lineItems[] =
        [
          "SelectionId" => "35175771",
          "TaxTypeId" => "6194291",
          "Description" => $invoiceItem->name,
          "Quantity" => $invoiceItem->duration,
          "UnitPriceExclusive" => $invoiceItem->total_excl_vat
        ];
    }

    foreach ($invoiceOtherItems as $invoiceOtherItem){
      $lineItems[] =
        [
           "SelectionId" => "35175771",
          "TaxTypeId" => "6194291",
          "Description" => $invoiceOtherItem->otherItem->name,
          "Quantity" => $invoiceOtherItem->quantity,
          "UnitPriceExclusive" => $invoiceOtherItem->total_excl_vat
        ];
    }

//dd($lineItems)

这里是向 API 发布数据的部分,我在其中发布发票项目(为简洁起见,此处删除了大部分项目):

$invoice = [
      "Date" => Carbon::now()->toDateString(),
      "Lines" => $lineItems,
      "DueDate" => "2021-08-29"
    ];

在我评论 dd 的地方执行转储和死亡会返回所有数组,但 API 告诉我需要行。我做错什么了吗?代码对我来说似乎是正确的,我在这件事上找不到任何帮助。

【问题讨论】:

  • 官方 API 文档是一个寻求帮助的好地方:developer.sage.com/api/accounting/api/invoicing-sales/… 乍一看好像是通过“Lines”,但应该是“invoice_lines”。
  • 它是“线条”。我已经设法自己解决了这个问题。我的代码没有任何问题,而是他们的 API 没有标准化。一些端点寻找编码的 JSON,而另一些则采用原始 JSON。他们的 API 文档在这种情况下毫无用处。

标签: arrays laravel laravel-7 sage-one


【解决方案1】:

对于任何可能遇到此问题的人,这里是解决方案:

在您的回复中,像这样定义您的标题:

'headers' => ['Content-Type' => 'application/json', 'Accept' => 'application/json']

不要使用form_params,而是使用这个:

'body' => json_encode($invoice)

【讨论】:

    猜你喜欢
    • 2019-11-12
    • 2019-09-05
    • 1970-01-01
    • 2016-06-22
    • 2015-09-19
    • 2017-10-13
    • 2015-10-08
    • 1970-01-01
    • 2021-04-25
    相关资源
    最近更新 更多