PHP Laravel Sage One API 说发票行存在且不为空时需要

PHP Laravel Sage One API says invoice lines are required when they are there and not empty

我目前正在将一个应用程序与 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)

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

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

在我评论 dd returns 所有数组的地方执行转储并死掉,但 API 告诉我需要行。我做错了什么吗?该代码对我来说似乎是正确的,但我找不到任何可以帮助解决这个问题的方法。

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

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

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

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

'body' => json_encode($invoice)