Http Request failed

Greetings everyone,

I've been attempting to retrieve payment configurations information via an HTTP request, but unfortunately, it's consistently failing.

I can confirm that my subscription is active. Strangely, when I test this functionality in the SKY API Console environment, it operates as expected. However, when attempting the same task through ASP.NET with VB.NET source code, I encounter difficulties.

Could it be that a specific framework is required for this operation? It's worth noting that I am not utilizing .NET Core. Below, I've provided a snippet of the code used. Unfortunately, it results in an error stating: {"error":"invalid_scope","error_description":"The scope parameter was not included in the request"}

Public Shared Sub Main()
ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol Or SecurityProtocolType.Tls12

Dim accessToken = GetAccessToken().GetAwaiter().GetResult()
Console.WriteLine("Access Token: " & accessToken)
End Sub

Public Shared Async Function GetAccessToken() As Task(Of String)
Dim httpClient As New HttpClient()
Dim clientId As String = ""
Dim clientSecret As String = ""
Dim requestBody As String = $"grant_type=client_credentials&client_id={clientId}&client_secret={clientSecret}"
'Dim response = Await httpClient.PostAsync("https://app.blackbaud.com/oauth/authorize?", New StringContent(requestBody, System.Text.Encoding.UTF8, "application/x-www-form-urlencoded"))
Dim response = Await httpClient.PostAsync("https://oauth2.sky.blackbaud.com/token", New StringContent(requestBody, System.Text.Encoding.UTF8, "application/x-www-form-urlencoded"))
Dim jsonResponse As String = Await response.Content.ReadAsStringAsync()
Dim accessToken As String = jsonResponse.Split(""""c)(3)
Return accessToken
End Function
End Class

Comments

  • Alex Wong
    Alex Wong Community All-Star
    Ninth Anniversary Kudos 5 Facilitator 3 bbcon 2025 Attendee Badge

    @Sumathi Babu
    Before anything else

    If these are you actual client id and secret, remove it from the post.

  • Ben Wong
    Ben Wong Blackbaud Employee
    Tenth Anniversary Kudos 3 Name Dropper Participant

    @Sumathi Babu the “invalid scope” error suggests that you don't have the right API scope set on the app. Here is the documentation on API scopes:

    It also looks like you have the “grant type” set to “client credentials”, which is only used for specific school apps using the One Roster API. The grant type should be “authorization code”, or “refresh token”.

    Hope that gets you in the right direction.

    Also, @Alex Wong is correct in that your “client secret” is a sensitive value and should be treated like a password. You should regenerate the client secret to secure your app and the data it's attempting to access.

    Thanks!

  • @Ben Wong Thanks Ben. I have now defined the scope. However, still getting Bad request message. The issue I'm encountering is that the applications I've created in My Applications list are not appearing in the authorization window. Do we need to adjust some settings for this? Please see the screenshot for reference.

    88024fef88c6085e2768ed17ea529580-huge-im

    The newly created applications are not listed in the console to test.

    9b8fc14072a8088dce28a96d2b67f2df-huge-im



  • Ben Wong
    Ben Wong Blackbaud Employee
    Tenth Anniversary Kudos 3 Name Dropper Participant

    @Sumathi Babu the SKY API Console is a different application that can be used to test SKY API calls to a particular environment. It cannot be used to make API calls on behalf of your application.

    Your application will need a UI to enable a user to initiate the authorization flow for your application to access the user's environment. The flow is described here:

    A tutorial can be found here:

    Hope that helps!


  • @Ben Wong Thank you for your reply.

    I've noticed that I'm receiving a response from the SKY API for my application only after configuring the RedirectUri. However, I'm unsure why this configuration is necessary. I don't intend to redirect after authorization; instead, I simply need the token from the response to utilize it for transactions via the API.

    Additionally, I've managed to test the API for my application using the .NET Core sample provided in the Git repository. However, I've encountered difficulties achieving the same functionality using the .NET 4.5 framework. Is it feasible to call the API using WebRequest (SOAP)? If so, could you provide an example?