Legacy Dev Forum Posts

 View Only

Sign Up

Client-side usage call UsersAPI function - not authenticated

  • 1.  Client-side usage call UsersAPI function - not authenticated

    Posted 06-05-2025 18:01

    Szlaski_Daniel | 2017-08-17 09:51:34 UTC | #1

    Hi,

    I've changed to the new version of the JS SDK, so I've included in script path: "<script type="text/javascript" src="purecloud-platform-client-v2.min.js"></script>"

    Next inside script.js I've added platformClient part:

    const platformClient = require('platformClient');

    Using ApiClient instance I log-in

    client = platformClient.ApiClient.instance; client.loginImplicitGrant(clientId, redirectUrl)

    Then I check if client contain accessToken - if yes, I call getMe function:

    var usersApi = new platformClient.UsersApi(); usersApi.getUsersMe()

    What is strange - I receive "{"status":401,"code":"bad.credentials","message":"Invalid login credentials."}"

    client object contain all tokens etc ... should I pass it somehow to the UserApi() ?

    Thanks Daniel


    kripette | 2017-08-17 11:04:24 UTC | #2

    Hi,

    Have you remembered to specify the correct Environment? (e.g mypurecloud.ie instead of mypurecloud.com)

    You do this before the login request by referencing client.setEnvironment('mypurecloud.ie'). This means that all subsequent API calls will use that Environment by default.

    For example: if you use https://apps.mypurecloud.ie/ as your login to PureCloud, then you'd set your environment to 'mypurecloud.ie'.

    There is no need to pass the Client to the UsersApi, each module has an internal reference to the Client.


    Szlaski_Daniel | 2017-08-17 13:14:24 UTC | #3

    Hi,

    Good finding! I've set Environment before login, but after that I'm redirerted to the same index.html page, and before call getUsersMe() function I didn't set it second time. I fixed that - it's working now !

    Thanks a lot !

    Daniel


    system | 2017-09-17 11:07:31 UTC | #4

    This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 1692