How can we make it easier for you to develop on top of Wild Apricot?

Using API on MS Access 2016

I extended the excel sample API V2 app to develop an attendance system for our club. For a number of reasons, we're working to move off of Excel and onto Access. The sample code from WA runs smoothly on Excel, but not on Access. The sample includes the following (in function GetOAuthToken)

Dim httpClient as IXMLHTTPRequest
Set httpClient = CreateObject("Msxml12.XMLHTTP.3.0")
httpClient.Open "POST", url, False

(where url = "https://oauth.wildapricot.org/auth/token")

The client.open returns 'unauthorized'. I cannot find any documentation on the open method of the httpclient object. And I have no idea what extra authorization I need when working in Access. As noted, this code runs with no problem when working in Excel. Both Excel and Access are in Office 2016 on Win 10

1 vote
Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)

We’ll send you updates on this idea

Russ Wolfe shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

3 comments

Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
Submitting...
  • Russ Wolfe commented  ·   ·  Flag as inappropriate

    Sub SetOAuthCredentials(httpClient As IXMLHTTPRequest)
    httpClient.setRequestHeader "User-Agent", "VBA sample app" ' This header is optional, it tells what application is working with API
    httpClient.setRequestHeader "Authorization", "Basic " + EncodeBase64("APIKEY:" + ApiKey) ' This header is required, it provides API key for authentication
    httpClient.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    End Sub

    Function GetOAUthToken(ByVal url As String) As String
    Debug.Print ("Loading data from " + url)
    Dim httpClient As IXMLHTTPRequest
    Set httpClient = CreateObject("Msxml2.XMLHTTP.3.0")
    httpClient.Open "POST", url, False
    SetOAuthCredentials httpClient

    httpClient.Send ("grant_type=client_credentials&scope=auto")

    If Not httpClient.Status = 200 Then
    msg = "Call to " + url + " returned error:" + httpClient.statusText
    Err.Raise -1, "GetOAUthToken", msg
    End If

    Dim resp As String
    resp = httpClient.responseText
    resp = Mid(resp, Len("{""access_token"":""") + 1, InStr(resp, """,""token_type""") - Len("{""access_token"":""") - 1)

    GetOAUthToken = resp
    End Function

Feedback and Knowledge Base