phprestguzzle

How can I add multiple query parameters with the same name but different values with Saloon (PHP)?


I integrated a remote API with my PHP web application using Saloon. I usually set my query parameter on my Request like this:

$this->query()->set([
  'param1' => 'val1',
  'param2' => 'val2',
  'param3' => ['val3', 'val4']
]);

This works perfectly and I get the expected URL/?param1=val1&param2=val2&param3[]=val3&param3[]=val4.

But now I'm dealing with a remote endpoint that expects multiple parameters with the same name and different values, as in /?param1=val1&param2=val2&param3=val3&param3=val4, How can I obtain this with Saloon?


Solution

  • My solution was to manually build the endpoint URL directly, so that my resolveEndpoint() returns the full URL /?param1=val1&param2=val2&param3=val3&param3=val4.

    It's definitely not the prettiest solution ever, but it gets the job done.