Hello,
I’m trying to execute below code to retrieve the users list. But I’m getting,
“Bad Request - Your browser sent a request that this server could not understand.” error.
$sUrl = 'https://[spoiler]dev-258743.okta.com[/spoiler]/api/v1/users?limit=25';
$request_headers = array();
$request_headers[] = 'Accept: application/json';
$request_headers[] = 'Content-Type: application/json';
$request_headers[] = 'Authorization: SSWS {{APIKEY}}';
$ch = curl_init($sUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
$response_body = curl_exec($ch);
If I execute the CURL from command prompt, it is working.
curl -v GET -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: SSWS {{APIKEY}}" "https://[spoiler]dev-258743.okta.com[/spoiler]/api/v1/users?limit=25"
dragos
June 25, 2019, 9:55am
2
Hi @amits.contentserv
I’ve tried now the following script on my end and it worked without any issues.
<?php
$sUrl = 'https://dragos.okta.com/api/v1/users?limit=25';
$request_headers = array();
$request_headers[] = 'Accept: application/json';
$request_headers[] = 'Content-Type: application/json';
$request_headers[] = 'Authorization: SSWS <REDACTED>';
$ch = curl_init($sUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$response_body = curl_exec($ch);
echo $response_body;
Hi @dragos ,
Thanks for your answer. Indeed, it is now working.
Though, it wasn’t for some reasons.
Okay, but my root issue is actually different, If I tried to filter the data based on the status, it is returning 1 always.
For example -
Instead
$sUrl = 'https://dev-258743.okta.com/api/v1/users?limit=25';
Use
$sUrl = 'https://dev-258743.okta.com/api/v1/users?filter=status+eq+"ACTIVE"&limit=25';
Can you please help me to resolve?
dragos
June 25, 2019, 10:30am
4
Hi @amits.contentserv
When using filtering on /api/v1/users endpoint, as mentioned here , the value of filter parameter should to be url encoded instead of escaped.
Regarding the result, can you please confirm if you have other users active in your Okta tenant?
1 Like
Great! It worked!
Though, I had used urlencode() to whole URL but seems it encoding would require only in parameters.
Thanks again!
system
Closed
January 17, 2024, 11:43pm
6
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.