Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dan3460's avatar

HTTP response from a API

I'm using the API from a company called Green Mile and the people there seem to be stumped. I'm making a request to one of the tables (RouteDriver), the documentation shows it should return the Driver ID among other things but only returns the Record Id and the Creation Date. Here is my call:

    public function getDriverAssigned(int $routeId)
    {
        return
            Http::withHeaders($this->headers)
            ->post($this->baseSite . 'RouteDriver/restrictions', [
                'attr'=> 'route.id',
                'eq' => $routeId,
            ])
            ->collect();
    }

and here is the answer:

[
{
"id": 84807,
"creationDate": "2022-03-09T07:32:20+0000"
}
]

It is the correct record as i can get in the database and check.

Has anyone experienced this problem before?

Thanks for any ideas.

0 likes
4 replies
Braunson's avatar

If Green Mile's API is returning the wrong information, surely it's up to them to look into. I would suggest confirming you are hitting the correct endpoint with the correct data provided. Dump out the $this->baseSite . 'RouteDriver/restrictions' to confirm the endpoint is correct, then make sure the payload keys and values are correct in what's expected by the Green Mile API.

dan3460's avatar

Thanks, sadly it is hitting the correct end point. I even try using tinker and got the same. I'll keep trying to get help from the Green Mile people.

dan3460's avatar

Here is the answer from GM support, i'm hoping that someone can translate to Laravel HTTP client request:

POST - https://seashore.greenmile.com/RouteDriver/filter?criteria=%7B%0A%20%20%22filters%22%3A%20%5B%0A%20%20%20%20%22%2A%22%2C%0A%20%20%20%20%22driver.id%22%2C%0A%20%20%20%20%22driver.name%22%0A%20%20%20%5D%0A%7D 

Criteria decoded:
{
  "filters": [
    "*",
    "driver.id",
    "driver.name"
   ]
}

Request:
{
  "route": {
    "id": 90679
  }
}
dan3460's avatar

In case any one is interested, i solved the issue this way:

  /**
     * Return drives assigned to the route.
     * @param int $routeId 
     * @return Collection 
     * @throws Exception 
     */
    public function getDriverAssigned(int $routeId)
    {
        $criteria = '{
            "filters": [
              "*",
              "driver.id"
             ]
          }
          ';
        return
            Http::withHeaders($this->headers)
            ->post($this->baseSite . 'RouteDriver/filter?criteria='.urlencode($criteria), [
                "route" => $routeId,
            ])
            ->collect();
    }

Looks a little ugly but it works.

Please or to participate in this conversation.