Zend certified PHP/Magento developer

How to send token for an API request along with custom post data

I have created a custom API endpoint and I have defined ACL for it. My API is working fine without ACL and I am able to post the data through API. But after defining the ACL now I need to receive the token and then make my POST request along with the token. But I am not sure how to pass the token along with the data. This is my custom script to test my API using curl.

custom-script.php

<?php
$data = array (
  'Orders' => 
    array (
     0 => 
      array (
       'ID' => 19558599,
       'Brand' => 'Brand',
       'Destination' => 'NextRDC',
       'DateTimeStamp' => '2021-01-05T20:37:29+00:00',
       'Currency' => 'GBP',
       'Items' => 
          array (
            0 => 
              array (
                'ItemID' => 12345678,
                'EAN' => '1234567890123',
                'BrandSKU' => '12345678',
                'Quantity' => 1,
                'PromiseDate' => '2021-01-09',
                'Price' => 67,
              ),
           ),
        ),
     ),
   )
 ;

$userData = array("username" => "*******", "password" => "**********");
$ch = curl_init("https://staging.nonnon.co.uk/rest/V1/integration/admin/token");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData))));

$token = curl_exec($ch);

$ch = curl_init("https://staging.nonnon.co.uk/index.php/rest/V1/matrid-nextapi/orders");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token)));

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($data))));

$result = curl_exec($ch);

return $result;
?>

You can see in the code I have passed the header for token but it is not working. I feel this is the wrong way to pass the token and I need to pass the token and the pOST data together, but I am not sure how to do it.

Could someone plz guide me with this.