okta / okta-sdk-php

PHP SDK for the Okta API
Apache License 2.0
38 stars 71 forks source link

Getting blank response all the time #34

Closed anilkumar-isol closed 6 years ago

anilkumar-isol commented 6 years ago

Hi there,

I have already used okta api with my own custom code but I'm using this sdk just to get custom attributes.

Question1: As we know that okta api doesn't return custom attributes for users until we update that object with post method. Also I read a discussion thread(https://support.okta.com/help/answers?id=906F0000000HzygIAC) says that Java-sdk return custom attributes with some (unmapped()) function so my question is, Is this sdk will return custom attributes without any extra efforts?

Question2: I have installed this sdk but when I tried to get a user, it always gives me a blank response. What should I have to do in this situation?

This is my code.

ini_set("display_errors",1);
error_reporting(E_ALL);
ini_set('display_startup_errors', TRUE);

include "vendor/autoload.php";
use Okta;

$okta = new Okta\Client('OrgName', 'API_TOKEN', [
    'preview'   => true,  // Use the okta preview (oktapreview.com) domain
]);

$user = $okta->user->get("00u5zrthay2733Fir0h7"); //user Id

echo "<pre>";print_r($user);echo "</pre>";die();

Please help me out.

Thanks in advance

bretterer commented 6 years ago

Hi @anilkumar-isol

For your code, you should use the ClientBuilder instead of creating a new instance of Client directly.

$client = (new \Okta\ClientBuilder())
            ->setToken('YourApiToken')
            ->setOrganizationUrl('https://dev-123456.oktapreview.com')
            ->build();

Once you are looking to get a user, the code below should work for you.

$user = new \Okta\Users\User();
$foundUser = $user->get('00u5zrthay2733Fir0h7');    //replace this id with the i
var_dump($foundUser);