kneidels kneidels - 8 days ago 6
reST (reStructuredText) Question

Setting up REST API in Classic ASP

I have the following REST API documentation, i am trying to see if this can be done in Classic ASP.

The destination URL is:

https://sandbox.cal-online.co.il/api/PayCalSDK/VerifyAndActivateForPaymentPage


{
TotalAmount: 1,
CurrencyCode: 1,
TransactionId: GUID,
Business: {
ApiKey: 'C89371AE-698F-4A15-BD35-2F58377A14F9', // test key
Description: ''
},
CreditTypes: [
{CreditTypeCode: 1, MaxNumberOfPayments: 1}
]
}


What I have is:

Set HTTP = CreateObject("MSXML2.serverXMLHTTP")
HTTP.setOption 2, 13056
HTTP.Open "GET", (url), false
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
HTTP.setRequestHeader "Business.ApiKey", "C89371AE-698F-4A15-BD35-2F58377A14F9"
HTTP.setRequestHeader "transactionId", "397653"
HTTP.setRequestHeader "PayCalSDK.CreditType", "1"
HTTP.setRequestHeader "TotalAmount", "20.20"
HTTP.setRequestHeader "CurrencyCode", "1"
HTTP.setRequestHeader "payCalSdkCharge.ApiUrlPath", "http://www.domain.com"
HTTP.send("")
Response.write HTTP.responseText
Set HTTP = nothing


But something is off with the format of the fields, because I am getting an error response from them:

Response is:

{"message":"An error has occurred."}


What is the correct syntax for this?

UPDATE:

I have also tried this code:

key = "C89371AE-698F-4A15-BD35-2F58377A14F9"

url = "https://m.cal-online.co.il/api/PayCalSDK/VerifyAndActivateForPaymentPage?"
str = "{ TotalAmount: 1, CurrencyCode: 1, TransactionId: 36985223, Business: { ApiKey: '" & key & "',Description: '' }, CreditTypes: [ {CreditTypeCode: 1, MaxNumberOfPayments: 1}] }"

Dim oXMLHttp
Set oXMLHttp=Server.Createobject("Msxml2.ServerXMLHTTP.6.0")
oXMLHttp.open "post", url & str,false

oXMLHttp.send
response.write oXMLHttp.responseText
Set oXMLHttp = Nothing


And i get the same response:

{"message":"An error has occurred."}

Answer

try this

key = "C89371AE-698F-4A15-BD35-2F58377A14F9"

url = "https://m.cal-online.co.il/api/PayCalSDK/VerifyAndActivateForPaymentPage?"
str = "{ TotalAmount: 1, CurrencyCode: 1, TransactionId: 36985223, Business: { ApiKey: '" & key & "',Description: '' }, CreditTypes: [ {CreditTypeCode: 1, MaxNumberOfPayments: 1}] }"

Dim oXMLHttp
Set oXMLHttp=Server.Createobject("MSXML2.ServerXMLHTTP.6.0")
oXMLHttp.open "POST", url,false
oXMLHttp.setRequestHeader "Content-Type", "application/json"
oXMLHttp.send str
response.write oXMLHttp.responseText
Set oXMLHttp = Nothing
Comments