Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > API Authentication >

Classic ASP

Started by Ben Snape -   in API Authentication

Has anyone managed to get the API working using Classic ASP? I had it working up until a month ago when Xero changed something and now my signature is always invalid...
Hey Ben

Without being very knowledgeable on ASP, the signature is just a hash of the values, so if it is coming back as invalid, there mush be something it is expecting and not getting.

Do you want to post up the function that creates the signature so we can see if we can figure it out?


Ronan Quirke (Community Manager)  

Hi Ronan, thanks for your comment. It's strange because it was working fine up to a month or so ago when you changed something in the signature varification or something. Anyway, here's the function that gets the signature:

Private Function Get_Signature()
Dim strBaseSignature : strBaseSignature = _
m_strMethod & "&" & _
Utils.URLEncode(m_strEndPoint) & "&" & _

Dim strSecret : strSecret = _
m_strConsumerSecret & "&" & _

Get_Signature = b64_hmac_sha1(strSecret, strBaseSignature)
End Function

Basically it is concatenating the method (POST etc) with the endpoint url and the post parameters, then the consumer secret and token secret are concatenated and they are used in the last bit to hash it.

Ben Snape  

Right, I've scrapped my previous code and started again. Still getting the invalid signature but I'm sure it's because I'm working out the base signature incorrectly. Can you please comment on my method below for requesting a request token:

1) setup my parameters

dim params : params = "oauth_callback=oob"
params = params & "&oauth_consumer_key="&consumerKey
params = params & "&oauth_nonce="&nonce
params = params & "&oauth_signature_method=HMAC-SHA1"
params = params & "&oauth_timestamp="&Set_Timestamp()
params = params & "&oauth_version=1.0"

2) get my base signature

dim baseSignature : baseSignature = "POST&"&encode(url)&"&"&encode(params)

3) Generate my signature

dim signature : signature = b64_hmac_sha1(consumerSecret, encode(baseSignature))

4) add the signature to the parameters

params = params & "&oauth_signature="&encode(signature)

5) Perform the post to the endpoint and I get invalid signature every time.

Ben Snape  

Right, I have it working at last. I can add a simple contact and that's fine, however I have a new problem. When I change to a GET and try and retrieve the contact details I get consumer_key_unknown error. Strange, I can add contacts etc but nor retrieve them.

Do you have to do something slightly different with a GET? I've changed the base signature from POST to GET etc but no joy...

Ben Snape  

Ignore that, I've managed to get it working. I wasn't formatting the GET url correctly...

Ben Snape  

Hi Ben. I'm trying to simply post invoices to xero from my classic ASP app. Are you able to post or email me example code please? Xero has none they can provide for classic ASP apparently. Cheers. thomas@sourceit.co.nz

Thomas Evans  

Hi Thomas, which part of the process do you need help with?

Ben Snape  

If its not too much trouble, everything needed to connect to Xero and send an invoice to my Xero account. Do I need to install a COM app on my server etc? I'm assuming its just a small amount of vbscript and would save me hours of figuring out. Maybe Xero could post it as example for Classic ASP along with other code they have too. Cheers.

Thomas Evans  

Hi, I'll try and put something together and post instructions here for you

Ben Snape  

First of all, here is a file with the specific functions needed. You need to include this file on any page dealing with the Xero API:

Function Set_OffsetMinutes()
Dim objWshShell : Set objWshShell = Server.CreateObject("WScript.Shell")
Set_OffsetMinutes = objWshShell.RegRead("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias")
Set objWshShell = Nothing
End Function

Function Set_Timestamp()
Dim dteFrom : dteFrom = "01/01/1970 00:00:00 AM"

Dim dteNow : dteNow = Now()
dteNow = DateAdd("n", Set_OffsetMinutes(), dteNow)

Set_Timestamp = DateDiff("s", dteFrom, dteNow)
End Function

Public Function encode(s)
if s <> "" then
Dim strTmpVal : strTmpVal = s
Dim strRetVal : strRetVal = ""
Dim intAsc : intAsc = 0
Dim strHex : strHex = ""

Dim i, strChr : For i = 1 To Len(strTmpVal)
strChr = Mid(strTmpVal, i, 1)

If InStr(1, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~", strChr) = 0 Then
intAsc = Asc(strChr)

If intAsc < 32 Or intAsc > 126 Then
strHex = encodeURIComponent(strChr)
strHex = "%" & Hex(intAsc)
End If

strRetVal = strRetVal & strHex
strRetVal = strRetVal & strChr
End If

encode = strRetVal
encode = ""
end if
End Function

Function Get_ResponseValue(strResponseText, strKey)
Dim arrPair, arrPairs : arrPairs = Split(strResponseText, "&")
Dim strRetVal : strRetVal = Null

Dim i : i = 0 : Do While i < UBound(arrPairs) + 1
arrPair = arrPairs(i)
arrPair = Split(arrPair, "=")

If arrPair(0) = strKey Then
strRetVal = arrPair(1)
Exit Do
End If

i = i + 1

Get_ResponseValue = strRetVal
End Function


Ben Snape  

I can't post some of the files because it is moaning that my answer is too long. Is anyone from Xero reading this? Could I possibly talk to someone re getting this code posted on your code examples page somewhere?

Ben Snape  

Hi Ben,

It might be best if you put it up on Github then we can add a link to it from our code sample page.


W. Abdullah (Community Manager)  

Sounds good, thanks.

Thomas Evans  

This is now done. See link below


Ben Snape  

Let me know how you get on!

Ben Snape  

Thanks for the code Ben. I actually just need to create a Private App. Would I just use the callback.asp part?

Thomas Evans  

Don't know I'm afraid, I've only looked at the public app side

Ben Snape  

Hi Ben.
I'm trying to simply login and post invoices to xero from my classic ASP app. Are you able to post or email me example code please? Xero has none they can provide for classic ASP apparently.
Cheers. Kapil.guleria@redblink.net. thanks in advance

Kapil Guleria  

Hi Ben,
i am trying to login and POST/GET invoices to xero from classic ASP web app. Are you able to email me example code? Please
Email: Rehan.tariq@freshmilksoftware.com

Simon Barney  

Hi, sorry I've migrated my websites to .Net and haven't kept the old Classic ASP ones.

Ben Snape  

no worries.
thanks for reply

Simon Barney  

Hello Simon,
Did you get anywhere by any chance finding any Classic ASP code for GET/POST please.
I've managed to get a token..
Thank you

Sharon Ball  

where is source code in the below location.There is only readme txt file.

manoj bisht  

Hi, I have no idea where the files have gone....we haven't touched that repository in 4 years. Unfortunately I didn't keep the source files because we moved to .Net years ago...sorry

Ben Snape  

Anybody here tried filesystem object on ASP Classic in accessing the certificates using private app?

Dudsky Mayao  

Anybody here tried API script - POST/GET invoices to xero from classic ASP web app ?.
Please email : sraju@conekter.com.au
Thanks in Advance

Selva Raju  

I know this is an old post, but I had need to figure this out, my solution is here.

David Eedle