Invalid login credentials

I have created a configured an oAuth client using Token Implicit Grant with a 48 hour token expiration and the following scopes...

conversations
notifications
outbound
user-basic-info
users:readonly

Every API request I attempt to make with the tokens returns an error...

	ErrorContent	"{\"message\":\"Invalid login credentials.\",\"code\":\"bad.credentials\",\"status\":401,\"contextId\":\"8863fd89-34b5-4bc6-a9b7-da669e0e76c7\",\"details\":[],\"errors\":[]}"	dynamic {string}

I am attempting the most basic of calls, getting user info and placing a call. And no, the tokens are not expired.

-- place a call
var client = new ConversationsApi();
client.Configuration.AccessToken = _accessToken;

            CreateCallRequest request = new CreateCallRequest
            {
                PhoneNumber = "1231231234",
                Priority = 0
            };

            try
            {
                CreateCallResponse result = client.PostConversationsCalls(request);
                Console.WriteLine(result.Id);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

-- get user info
var usersApi = new UsersApi();
usersApi.Configuration.AccessToken = _accessToken;

            var me = await usersApi.GetUserAsync("user_name");

What am I missing?

Oops. I forgot to specify the region...

            PureCloudRegionHosts region = PureCloudRegionHosts.us_west_2;
            Configuration.Default.ApiClient.setBasePath(region);

Hi Mark,

You seems to be getting a little confused about the authentication. The can authenticate yourself at the start of your program by setting your OAuth id and secret on the client like you did with the region. You do not need to authenticate with each API class. Here's an example using Oauth id and secret.

using System;
using System.Diagnostics;
using PureCloudPlatform.Client.V2.Api;
using PureCloudPlatform.Client.V2.Client;
using PureCloudPlatform.Client.V2.Model;
using PureCloudPlatform.Client.V2.Extensions;

PureCloudRegionHosts region = PureCloudRegionHosts.us_east_1; // Genesys Cloud region
Configuration.Default.ApiClient.setBasePath(region);

var accessTokenInfo = Configuration.Default.ApiClient.PostToken("OAuth-id", "OAuth-secret");
var apiInstance = new UsersApi();

try
{ 
    UserEntityListing result = apiInstance.GetUsers(25, 1);
    Console.WriteLine(result.ToJson());
}
catch (Exception e)
{
    Debug.Print("Exception when calling Users.GetUsers: " + e.Message );
}

Regards,
Declan

Hi Declan,

Placing phone calls is my actual goal. I have read that the Client Authentication method, which you have shown, will not work for this and I need to use a User authentication method. Can the access token for the user be posted at a single point in the app as well, or would it need to be applied at every instantiation of a new ConversationsApi like...

var client = new ConversationsApi();
client.Configuration.AccessToken = _accessToken;

Hi

You can apply the AccessToken to the configuration object once and it should be good for the Rest of the API calls. Can you elaborate on the AccessToken how you received it ? That could be the problem for your invalid login credentials Issue.

The Invalid login issue was due to not setting the region. Everything works fine now. The client.Configuration.AccessToken property isn't static so I was assuming it would need to be set every time the ConversationsApi was instantiated.

Thanks

1 Like

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