AJAX要求Linnworks

I am using Laravel to create an app for the Linnworks API. I have created my own AJAX requests in PHP that receive the data from javascript.

This is a working request.

Linnworks Example

inventoryItemId=28c6226d-08de-4eb5-9bf1-f6089972cf18&fieldName=0&fieldValue=sample string 1&locationId=e10f6f45-d4ad-4128-8b58-6ff84b23199a

Javascript Request to PHP

var itemArray = 
{
    "inventoryItemId": "39692932-f8b0-42d7-9419-0500d6d79769",
    "fieldName": "StockLevel",
    "fieldValue": 6,
    "locationId": "00000000-0000-0000-0000-000000000000"
};

var itemArrayStr = JSON.stringify(itemArray);

AjaxRequestNew({'dataArray': itemArrayStr, 'linnworksURL': 'Inventory/UpdateInventoryItemLevels'});

function AjaxRequestNew(ajaxData) {
$.ajax({
    headers: {'X-CSRF-TOKEN': mytoken},
    url: '/api-linnworks-request',
    method: 'post',
    data: ajaxData,
    async: false,
    complete: function (data) {
        resp = data.responseText;
    }
});
}

PHP AJAX Request

public function apiLinnworksRequest(Request $request){
$url ='https://eu1.linnworks.net//api/'.$request->linnworksURL;
$data = json_decode($request->dataArray);

$myvar = WebController::linnworksRequestNew($url, $data , $request);
}

public function linnworksRequestNew($url, $data , $request) {
$client = new Client();
// dd($data);

$res = $client->request(
    'POST', $url, [
    'headers' => [
        'Authorization' => $request->session()->get('LinnReturnToken')
    ],
    'form_params' => $data
]);
var_dump($res->getBody()->__toString());
}

This works and will update the stock levels of the item, however I need to update multiple items at the same time. I have found that Stock /SetStockLevel meets my requirements, however I can not format the request correctly and keep getting an error.

Linnworks Example

 stockLevels=[
{
    "SKU": "sample string 1",
    "LocationId": "2260b419-69dd-4586-b2b2-08db9591921c",
    "Level": 3
},
{
    "SKU": "sample string 1",
    "LocationId": "2260b419-69dd-4586-b2b2-08db9591921c",
    "Level": 3
}
]

Thanks to help from Linnworks and by using Postman, I have found that the request needs to be formatted in the following format.

PHP

 'stocklevels' => 
     '[ { "SKU": "SUIT-4PC-[philip / paisley]-BLACK-02yrs", ]
     "LocationId": "00000000-0000-0000-0000-000000000000", 
     "Level": 3 }, { "SKU": "SUIT-4PC-[philip / paisley]-BLACK-03yrs", 
     "LocationId": "00000000-0000-0000-0000-000000000000", 
     "Level": 3 } ]'

To replicate this I have sent the data from Javascript in the following format:

JS

var itemArray = 
    [
        {
            "SKU": "SUIT-4PC-[philip / paisley]-BLACK-02yrs",
            "LocationId": "00000000-0000-0000-0000-000000000000",
            "Level": 6
        },
        {
            "SKU": "SUIT-4PC-[philip / paisley]-BLACK-03yrs",
            "LocationId": "00000000-0000-0000-0000-000000000000",
            "Level": 6
        }
    ];

    var itemArrayStr = JSON.stringify(itemArray);
    var dataRequest = {stocklevels: itemArrayStr};