kieran
kieran

Reputation: 2312

Passing an array as a query string parameter for an API

I have some API instructions I am trying to follow

(string) source (string) key (string) params[file] (string) params[gender] (int) params[age]

I get how to make the API calls but where it has an array for params (file, gender and age) how to I put that into a query string?

The call works with something like this:

GET https://api-url.com/api?source=lorem&key=dolor

But how would I append that with the params? params[file]=file_name.gif ??

That doesn't seem to work but I'm open to the fact something else could be wrong - just wanted to check how you pass an array in a query string?

Thanks

Upvotes: 1

Views: 2733

Answers (1)

Floern
Floern

Reputation: 33904

Yes it's params[file]=xy in the query string:

your-url/api?source=lorem&key=dolor&params[file]=file_name.gif&params[age]=23..

Access in PHP: $yourfile = $_GET['params']['file'];

Upvotes: 3

Related Questions