Legacy Dev Forum Posts

 View Only

Sign Up

  • 1.  Sample Code from Website

    Posted 06-05-2025 18:10

    Kennytlaloc | 2016-06-14 14:06:17 UTC | #1

    In the sample code below....

    UserMe me = usersApi.getMe(Arrays.asList("presence"));

    This keeps returning a Null Pointer Exception because usersApi.getMe(....) is returning null.

    In my code I am using api.mypurecloud.com instead of api.mypurecloud.ie

    Configuration.getDefaultApiClient().setBasePath("https://api.mypurecloud.com"); Configuration.getDefaultApiClient().setAccessToken("using My Access Token here");

    Any suggestions on how I can connect to my org and return this info?

    Example from the Website:::

    // Set access token Configuration.getDefaultApiClient().setAccessToken("BL4Cb3EQIQFlqIItaj-zf5eyhAiP964kucEuOI1g54dKQIgd24P99ojbFHtpgUTudRIkuUYfXMy0afEnZc5nEQ");

    // Set environment Configuration.getDefaultApiClient().setBasePath("https://api.mypurecloud.ie");

    // Instantiate API UsersApi usersApi = new UsersApi();

    // Get the logged in user UserMe me = usersApi.getMe(Arrays.asList("presence")); System.out.println("Hello " + me.getName());


    tim.smith | 2016-06-14 14:07:33 UTC | #2

    Which OAuth flow did you use to get that access token?


    Kennytlaloc | 2016-06-14 15:04:19 UTC | #3

    I used Postman to get the Token and I pasted that into the code.


    tim.smith | 2016-06-14 16:06:04 UTC | #4

    But which OAuth type are you using? Implicit Grant, Authorization Code Grant, or Client Credentials Grant?


    Kennytlaloc | 2016-06-14 16:46:24 UTC | #5

    The Grant Type is set at Code Authorization.


    tim.smith | 2016-06-14 17:39:32 UTC | #7

    The only time I've seen that is when you're using a token from a client credentials grant; there is no person context for client credentials and therefore /users/me returns nothing. This should be working with code authorization.

    Can you try grabbing the latest JAR file from github and try with that? The JAR file is located at https://github.com/MyPureCloud/purecloud_api_sdk_java/tree/master/build/target (as of a few minutes ago). It should be on maven central this week.

    For reference, here's my full application I tested with:

    package com.inin;

    import com.mypurecloud.sdk.ApiException; import com.mypurecloud.sdk.Configuration; import com.mypurecloud.sdk.api.UsersApi; import com.mypurecloud.sdk.model.User; import com.mypurecloud.sdk.model.UserMe; import com.mypurecloud.sdk.model.UsersEntityListing;

    import java.util.Arrays;

    public class Main {

    public static void main(String[] args) { try { Configuration.getDefaultApiClient().setAccessToken("my token"); Configuration.getDefaultApiClient().setBasePath("https://api.mypurecloud.com");

    UsersApi usersApi = new UsersApi();

    UserMe me = usersApi.getMe(Arrays.asList("presence")); System.out.println("Hello " + me.getName());

    UsersEntityListing users = usersApi.getUsers(25, 1, null, null, Arrays.asList("presence")); System.out.println("\nKnown users:"); for (User user : users.getEntities()) { System.out.println(user.getName()); } } catch (ApiException e) { e.printStackTrace(); } } }


    Kennytlaloc | 2016-06-14 19:18:52 UTC | #8

    I did add the new version. Blew out the existing files and re-imported and it now works.

    Thanks


    system | 2017-08-28 19:24:47 UTC | #9


    This post was migrated from the old Developer Forum.

    ref: 64