Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending [] in URL Query Params get encoded #88

Open
ajtrichards opened this issue Jul 14, 2020 · 1 comment
Open

Sending [] in URL Query Params get encoded #88

ajtrichards opened this issue Jul 14, 2020 · 1 comment

Comments

@ajtrichards
Copy link

ajtrichards commented Jul 14, 2020

I'm trying to use this library to interact with the Zendesk API. Using the following code, I'm requesting the Users endpoint with some query params in the URL ?role[]=agent&role[]=admin

However, when I have this code I get an error response back from Zendesk saying the params aren't correct.

Request to API

$req = Zttp::withHeaders([
    'Authorization' => 'Bearer MYTOKEN',
])->get('https://MYSUBDOMAIN.zendesk.com/api/v2/users.json?role[]=agent&role[]=admin');

dd($req->json());

Error from API

^ array:1 [▼
  "error" => array:2 [▼
    "title" => "Invalid attribute"
    "message" => "You passed an invalid value for the role attribute. Invalid parameter: role must be a string from api/v2/users/index"
  ]
]

If I look at the URL which Zttp actually sends it appears as:
https://MYSUBDOMAIN.zendesk.com/api/v2/users.json?role%5B0%5D=admin&role%5B1%5D=agent

I have also tried using:

    $req = Zttp::withHeaders([
        'Authorization' => 'Bearer MYTOKEN',
    ])->get('https://MYSUBDOMAIN.zendesk.com/api/v2/users.json', [
        'role' => 'admin',
        'role' => 'agent',
    ]);

and

    $req = Zttp::withHeaders([
        'Authorization' => 'Bearer MYTOKEN',
    ])->get('https://MYSUBDOMAIN.zendesk.com/api/v2/users.json', [
        'role[]' => 'admin',
        'role[]' => 'agent',
    ]);

Using this approach, Zendesk get's only one of the parameters.
Does anyone have any suggestions how I can get this working? Via the query params is the only way Zendesk will accept.

@jonbaldie
Copy link

Have you tried sending the roles as an array instead?

$req = Zttp::withHeaders([
    'Authorization' => 'Bearer MYTOKEN',
])->get('https://MYSUBDOMAIN.zendesk.com/api/v2/users.json', [
    'role' => ['admin',  'agent'],
]);

Those last two examples won't work because they're defining duplicate keys on a PHP array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants