0

I'm trying to fetch data by GET request with using Guzzle client. I'm using both header with JWT token and query params like below:

function fetchUserByEmployeeId(string $employeeId): JsonResponse
    {
        $headers = $this->getHeaders();
        $query = ['$filter' => "employeeId eq $employeeId", '$select' => 'displayName,givenName,postalCode,employeeId,id'];
        try {
            $result = $this->client->request('GET', self::FIND_USER_BY_EMPLOYEE_ID_URL, [
                'headers' => $headers,
                'query' => $query,
                'debug' => true
            ]);
            return JsonResponse::fromJsonString($result->getBody()->getContents());
        } catch (RequestException $exception) {
            throw $exception;
        }
    }

Unfortunaletely I've received an error like below: enter image description here

If I delete $query it will work. Is there something wrong with my query params? I have no idea. Based on Guzzle documantation it seems to be ok: https://docs.guzzlephp.org/en/stable/request-options.html#query

Krzysztof Michalski
  • 791
  • 1
  • 9
  • 25

1 Answers1

0

Fortunately I have solved this issue. Problem was with passing param. $employeeId, should be in quotes. Like below:

function fetchUserByEmployeeId(string $employeeId): JsonResponse
    {
        $headers = $this->getHeaders();
        $query = ["\$filter" => "employeeId eq '$employeeId'", "\$select" => "displayName,givenName,postalCode,employeeId,id"];
        try {
            $result = $this->client->request('GET', self::FIND_USER_BY_EMPLOYEE_ID_URL, [
                RequestOptions::HEADERS => $headers,
                RequestOptions::QUERY => $query,
                'debug' => true
            ]);
            return JsonResponse::fromJsonString($result->getBody()->getContents());
        } catch (RequestException $exception) {
            throw $exception;
        }
    }
Krzysztof Michalski
  • 791
  • 1
  • 9
  • 25