Drupal Http API Client and howto pass form-params with options as body to Get Request API Call

Jun
2020
25
Recently i had to make a GET API request with some params (form-params) to the body of the API request call. This is what worked for me:
<?php
 
public function poi_call(int $id,$timestamp_start = '2020-01-01 00:00:00',$timestamp_end = '2020-12-01 00:00:00') {

    try {

     
$options =  [
       
'form_params' => [
         
//%Y-%m-%d %H:%M:%S
         
'timestamp_start' => $timestamp_start,
         
'timestamp_end' => $timestamp_end,
        ],
      ];

     
$response = $this->client->get('poi/'.$id.'/stats',$options);
     
$data = Json::decode($response->getBody());
      return
$data;
    }
    catch (
RequestException $e) {
     
watchdog_exception('people_flow_module', $e);
    }

  }
?>
You can pass the body params with the $options array variable as ['form_params'].
Cats: 
this is an arrow pointing back to the top of the page