Create Debtor – Classic ASP

ASP (classic)

<% '/// Include json converter - http://www.aspjson.com %>
<!--#include file="aspJSON1.17.asp" -->
<%
Const apiUrl = "https://api.winkas.net/api/"
Dim apiMethod
Dim requestBody
Dim apiResponse
Dim responseBody
Dim responseStatus
Dim responseMessage
Dim httpService
Dim token

'/// Get access token

apiMethod = "Authentication/Authenticate"

Set requestBody = New aspJSON

With requestBody.data
	.Add "UserName", "xxxxx"
	.Add "UserPassword", "xxxxx"
	.Add "UserContractCode", "xxxxx"
End With

Set httpService = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
httpService.open "POST", apiUrl & apiMethod
httpService.setRequestHeader "Content-Type", "application/json; charset=utf-8"
httpService.send requestBody.JSONoutput
apiResponse = httpService.responseText

Set responseBody = New aspJSON
responseBody.loadJSON apiResponse

responseStatus = responseBody.data("WinKasStatus")
responseMessage = responseBody.data("WinKasMessage")

If responseStatus <> 0 Then 
	Response.Write "<p>Authentication failed!</p>"
	Response.Write "<p>" & responseMessage & "</p>"
	Response.End
End If

token = responseBody.data("WinKasData").item("CurrentToken")



'/// Create Debtor

apiMethod = "Debtors/Create"

Set requestBody = New aspJSON

With requestBody.data
	.Add "Token", token
	.Add "Data", requestBody.Collection()
	With .item("Data")
		.Add 0, requestBody.Collection()
		With .item(0)
			.Add "Name", "Felt01"
			.Add "Value", "Kurt"
		End With
		.Add 1, requestBody.Collection()
		With .item(1)
			.Add "Name", "Felt02"
			.Add "Value", "Engvejen 199"
		End With
	End With
End With

httpService.open "POST", apiUrl & apiMethod
httpService.setRequestHeader "Content-Type", "application/json; charset=utf-8"
httpService.send requestBody.JSONoutput
apiResponse = httpService.responseText

Set responseBody = New aspJSON
responseBody.loadJSON apiResponse

responseStatus = responseBody.data("WinKasStatus")
responseMessage = responseBody.data("WinKasMessage")

If responseStatus <> 0 Then 
	Response.Write "<p>Create Debtor failed!</p>"
	Response.Write "<p>" & responseMessage & "</p>"
	Response.End
Else
	Response.Write "Debtor Created!"
End If




Set requestBody = nothing
Set responseBody = nothing
Set httpService = nothing
%>