arrayslaravellaravel-7sage-one

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


I am currently integrating an application with the Sage One API and am having a problem. The API says that invoice lines may not be empty, but the data is there. What am I doing wrong?

Here is my method of getting the line items:

$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)

And here is the part in the post data to the API where I post the invoice items (removed majority items for the sake of brevity here):

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

Performing a dump and die where I commented the dd returns all the arrays, yet the API is telling me lines are required. Am I doing anything wrong? The code seems correct to me and I can't find anything to help on this matter.


Solution

  • For anyone that might run across this problem here is the solution:

    In your response, define your headers like this:

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

    And do not use form_params, but use this instead:

    'body' => json_encode($invoice)