C# Authorization Error

Hello,

We placed a manual call to a phone number and it’s showing up in the Developer Web API, but not in the C# client (code below). We decided to try and not use the C# SDK and make a straight POST, but it’s not quite clear how Auth is done as per the documentation. It would be great to get a sample POST so that we can get a token (we’ve only ever used the SDK). It would be even better if the SDK worked.

var dailyConversationQuery = new ConversationQuery()
{
Interval = "2020-09-15T00:00:00.000Z/2020-09-16T00:00:00.000Z",
};

AnalyticsConversationQueryResponse conversationQuery = outbound.PostAnalyticsConversationsDetailsQuery(dailyConversationQuery);

I am using the following SDK API to generate an access token:

Configuration.Default.AccessToken = Configuration.Default.ApiClient.PostToken(clientId, clientSecret).AccessToken

The parameters I’m passing are the clientId and clientSecret. It works for the APIs that are using the SDK. The auth error we are receiving pertains to making manual API calls and adding the configuration token to a header. The token shows a value so we’re unsure of what the issue is.

System.FormatException: The header name format is invalid.

This is how the header is being formatted:

client.DefaultRequestHeaders.Add( "Authorization: Bearer" , Configuration.Default.AccessToken);

Please advise.

thanks!
Peter

Please refer to the authorization documentation for how to manually authorize an app: https://developer.mypurecloud.com/api/rest/authorization/use-client-credentials.html

You can also refer to the SDK's source code to see how it's making the request: https://github.com/MyPureCloud/platform-client-sdk-dotnet/blob/master/build/src/PureCloudPlatform.Client.V2/Extensions/AuthExtensions.cs#L24.

This is incorrect. The header name is authorization, not authorization: bearer. That code is adding part of the header value to the name.

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