This works for me (I edited my code a little to show):
// First log in
$url = 'http://[your-domain]/rest/V1/integration/admin/token';
$body = '{"username":"user", "password":"pass"}';
$header = 'Content-type: application/json';
$options = [ 'method' => 'POST',
'content' => $body,
'header' => $header
];
$context = stream_context_create(['http' => $options]);
$token = json_decode(file_get_contents($url, false, $context));
// Some settings
$header = 'Authorization: Bearer ' . $token . "\r\n"
. 'Content-type: application/json';
$options = [ 'method' => 'GET',
'content' => $body,
'header' => $header
];
$context = stream_context_create(['http' => $options]);
$url = 'http://outpro.lt[your-domain]/index.php/rest/V1/orders/'
. '?searchCriteria[filter_groups][0][filters][0][field]=status&searchCriteria[filter_groups][0][filters][0][value]=pending'
//. '&searchCriteria[sortOrders][0][field]=increment_id' // To sort Desc
. '&fields=items[increment_id,entity_id]';
//print file_get_contents($url, false, $context) . "\n"; // Check full json if you want
// Generate json output
$json_contents = file_get_contents($url, false, $context) . "\n";
$order = json_decode($json_contents);
$answer = '{';
if ($order->items) {
foreach($order->items as $key => $value) {
$answer .= '"'. $value->entity_id . '":"' . $value->increment_id . '",';
}
$answer = substr($answer,0,strlen($answer)-1);
$answer .= '}';
echo $answer;
}