Providing Authentication Information via msxml2.ServerXMLHTTP

I am using Classic ASP and am trying to use the JustGiving API.

I would like to use it to display the total received and the total donations received on my donations page on my website.

I see that information is available via: https://api.justgiving.com/docs/resources/v1/Account/Retrieve

<%
vurl = "http://api.justgiving.com/---myIDhere---/v1/account"
Set http = Server.CreateObject("msxml2.ServerXMLHTTP")
http.Open "GET", vurl, False
http.Send

Set dom = Server.CreateObject("msxml2.DOMDocument")

dom.loadXML http.responseText

Set items = dom.getElementsByTagName("account")

For Each item In items

    Set var_totalDonated = item.getElementsByTagName("totalDonated")
    If NOT (var_totalDonated IS Nothing) Then
        var_totalDonated = ap(totalDonated(0).Text)
        response.write var_totalDonated
    End If

Next
%>

      

However, the page doesn't work when I access it.

I think because I need to provide some authentication information as described here: https://api.justgiving.com/docs/usage#protectedResources

So I got this authentication information.

But I have no idea how to "send" it to the API so that it can authenticate me as a user and provide information.

It also mentions providing header information on the link above this one (I can't post the link as I don't have enough reputation), but replace #protectedResources at the end of the url with #contentTypes.

Sorry, am I missing something on this side too?

Sorry if I'm asking stupid questions, but the API docs information suggests some level of intelligence on the part of the user, and I don't have it!

Any advice is greatly appreciated.

thank


Thanks to John for your answer.

Based on this, I changed the code to:

<%
vurl = "https://api.justgiving.com/API_KEY/v1/account"
Set http = Server.CreateObject("msxml2.ServerXMLHTTP")
http.Open "GET", vurl, False, "username", "pwd"
http.setTimeouts 5000, 5000, 10000, 10000 ''ms - resolve, connect, send, receive
http.setRequestHeader "Authorization", "Basic MY_AUTH_STRING"
http.Send

Set dom = Server.CreateObject("msxml2.DOMDocument")

dom.loadXML http.responseText

Set items = dom.getElementsByTagName("account")

For Each item In items

    Set var_totalDonated = item.getElementsByTagName("totalDonated")
    If NOT (var_totalDonated IS Nothing) Then 
        var_totalDonated = (var_totalDonated(0).Text)
        response.write var_totalDonated
    End If

Next
%>

      

But unfortunately the page still doesn't work.

I check also via: groups.google.com/forum/#! Theme / justgiving-api / Xhz5Fkxuy1s

But there is no answer yet.

Thanks again


Fixed version

<%

Sub debug( varName )
    Dim varValue
    varValue = Eval( varName )
    response.write "<p style='margin:10px; border-bottom:2px solid #ccc;border-top:1px solid #eaeaea;background-color:white;padding:10px;color:red;text-align:left;'><strong>" & varName & "</strong>: " & varvalue & "</p>" & vbcrlf & vbcrlf
End Sub

vurl = "https://api.justgiving.com/AP_KEY/v1/account"
Set http = Server.CreateObject("msxml2.ServerXMLHTTP")
http.Open "GET", vurl, False, username, password
http.setTimeouts 5000, 5000, 10000, 10000 'ms - resolve, connect, send, receive
http.setRequestHeader "Authorization", "Basic AUTH_STRING"
http.Send

Response.ContentType = "application/xml"

Set dom = Server.CreateObject("msxml2.DOMDocument")

dom.loadXML http.responseText

Set items = dom.getElementsByTagName("account")

For Each item In items

    Set var_totalDonated = item.getElementsByTagName("totalDonated")
    If NOT (var_totalDonated IS Nothing) Then 
        var_totalDonated = ap(var_totalDonated(0).Text)
        debug "var_totalDonated"
    End If

    Set var_totalRaised = item.getElementsByTagName("totalRaised")
    If NOT (var_totalRaised IS Nothing) Then 
        var_totalRaised = ap(var_totalRaised(0).Text)
        debug "var_totalRaised"
    End If

    Set var_totalGiftAid = item.getElementsByTagName("totalGiftAid")
    If NOT (var_totalGiftAid IS Nothing) Then 
        var_totalGiftAid = ap(var_totalGiftAid(0).Text)
        debug "var_totalGiftAid"
    End If

Next
%>

      

I used to use:

vurl = "https://api.justgiving.com/AP_KEY/v1/account"

      

But when I changed it to https it worked.

I thought I had tried this before, but obviously I haven't.

Thanks again John, I really appreciate your help!

+2


source to share


2 answers


Try

http.Open "GET", vurl, False, "yourusername", "yourpassword"

      

I don't know if this works on justgiving, but it works with the Bing API

Also, this question could be XmlHttp Request Basic Authentication Issue



Edit - using Response.ContentType and Msxml2.ServerXMLHTTP.6.0

vurl = "https://api.justgiving.com/API_KEY/v1/account"
Set http = Server.CreateObject("msxml2.ServerXMLHTTP.6.0")
http.Open "GET", vurl, False, "username", "pwd"
http.setTimeouts 5000, 5000, 10000, 10000 'ms - resolve, connect, send, receive'
http.setRequestHeader "Authorization", "Basic MY_AUTH_STRING"
http.Send

Response.ContentType = "application/xml"    

Set items = http.responseXML.getElementsByTagName("account")

      

etc.

+8


source


Sorry for adding to the old post. However, this comes up all the time when Googling helps with MailChimp API V3.0 and VBA.

This is the fix I used:

ret = objhttp.Open("POST", sURL, False) 
objhttp.setRequestHeader "Content-Type", "application/json"
objhttp.setRequestHeader "Accept", "application/json"

'V3 API uses HTTP Basic Authorisation inside an https: wrapper.
'The standard windows method does not seem to work however the 
'following hack does.
'In summary the user name and APIkey are seperated with a Colon: and 
'base 64 encoded and added to a Http RequestHeader


objhttp.setRequestHeader "Authorization", "Basic " & Base64Encode(APIUser & ":" & ApiKey)

objhttp.send (sJson)

      



You will need to encode the Base64Encode function. I took the code from http://pastie.org/1192157 (Ex StackOverflow) and pasted it into a VBA module.

Hope it helps.

0


source







All Articles