Hi,
Has anyone successfully integrated the API with classic asp?
I've written this so far
sha256 is a function that should be an equivalent to the one in the sample php code.Code:Dim xmlHttp,xmldom,salt,signature,encodedSignature Set xmlHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP") set xmldom = server.CreateObject("Microsoft.XMLDOM") apikey="90d83596-150a-56a4-f5f7-4sdzb7f05d12" secretkey="MjIxN2RmZWYtZGYxZi05YzM0LTQ5sda12Y5ZjJiODRhMzIwMzYwOTY4NDItZTExNi0wNzQ0LTU5MDItMTg4YmE4NzllOWU4" salt=generatePassword(6) signature= sha256(salt&secretkey) encodedSignature =Base64Encode(signature) encodedSignature = server.URLEncode(encodedSignature) XMLHTTP.Open "POST", "mydomain.kayako.com/api/index.php?e=/Core/Test", apikey, salt, false xmlHTTP.setRequestHeader "Content-Type", "text/xml" xmlHTTP.setRequestHeader "Authorization", "Basic " & Base64Encode(apikey & ":" & secretkey ) xmlHTTP.send
Salt also is a function to generate a random password.
This code shoots back 401 unauthorized. Not sure where to debug this. The request headers are probably bad i suppose.
Classic ASP and kayako API
Discussion in 'Developing, APIs and extending' started by mrfusion, Nov 22, 2011.
-
mrfusion New Member
mrfusion, Nov 22, 2011#1 -
Rini New Member
I'm setting up API with asp classic. I now have successfully created a GET request. The apikey, salt and signature should be in the url and you should remove the Authorization request header.
Rini, Nov 14, 2012#2 -
Rini New Member
Here a function to post data using ASP classic. Below the function there is a example of posting a ticket in Kayako, using this function.
Function PostFormdata(Url, Data)
Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP")
httpRequest.Open "POST", Url, False
httpRequest.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
httpRequest.Send sata
PostFormdata = httpRequest.Status & " " & httpRequest.ResponseText
End Function
' Here is what we need to get authorized
apiKey = "apikey"
salt = "salt"
signature ="signature"
' We send the data to the following URL. In this example we create a new ticket
strUrl = "https://example.domain.com/api/index.php?e=/Tickets/Ticket"
'Now define the authorization string
strAuthorization = "apikey=" & apikey &"&salt=" & salt & "&signature="& signature
'Here we define the string that contains the data that we need to post.
strData = "&subject=" & strSubject & "&fullname=" & strFullname & "&email=" & stremail & "&contents="& strContents & "&departmentid=" & numDepartmentID & "&ticketstatusid=" & numTicketStatusID & "&ticketpriorityid="& numTicketPriorityID& "&tickettypeid="& numTicketTypeID & "&autouserid=" & numAutoUserID & "&staffid=" & numStaffID & "&ignoreautoResponder="& numIgnoreAutoResponder
' Now prepare the string we will send. Consists of Authorization and the Data string
strPostData = strAuthorization & strData
' Now we are ready to call the function.
CreateTicket= PostFormdata(strUrl, strPostData)
' Read back the result
response.write CreateTicket
That's it!
You can easily customize this for other API calls. Modify strData with the data you want to send and modify strURL with the URL you want to post the data.Rini, Nov 16, 2012#3
Share This Page
Tweet
- Login with Facebook
-
Forgot your password?
-