“Original” CURL:
curl --location --request POST ‘https://myspotlight.app/api/int/insert-transaction-v2’
–data-raw ‘{
“apikey”: “SL-0a9e160bfec9-f69a94c16fa7-7634627146c0”,
“p_id”: “105”,
“p_orgjed”: “10”,
“p_pan”: “00750000000011”,
“p_user_id”: “100”,
“p_iznos_racuna”: 50,
“p_iznos_bez_ak”: 0,
“p_iznos_placen_bp”: 1,
“p_iznos_placen_pp”: 5,
“p_komentar”: “”,
“stavke”: [
{
“rbr”: 1,
“artikal”: “14”,
“kolicina”: 1,
“popust”: 0,
“iznosMP”: 50
}
],
“vauceri”: { “1”:{“kod”:“000001002005978451”} }
}’
Libcurl from HTTPWebServices.app (C6.3)
Send:CustomRequest=‘POST’
SSLInfo:bUseSSL= true
SendRequest ROUTINE
DATA
curl TCurlHttpClass
res CURLcode
qIndex LONG, AUTO
respBuffer &IDynStr
CODE
respBuffer &= NewDynStr()
curl.Init()
curl.FreeHttpHeaders()
IF RECORDS(HttpHeaders)
LOOP qIndex = 1 TO RECORDS(HttpHeaders)
GET(HttpHeaders, qIndex)
curl.AddHttpHeader(HttpHeaders.HttpHeader)
IF res <> CURLE_OK
MESSAGE('AddHttpHeader failed: '& curl.StrError(res), ‘libcurl’, ICON:Exclamation)
END
END
res = curl.SetHttpHeaders()
IF res <> CURLE_OK
MESSAGE('SetHttpHeaders failed: '& curl.StrError(res), ‘libcurl’, ICON:Exclamation)
END
END
IF bGetServerResponse
res = curl.SetHttpGET(TRUE)
IF res <> CURLE_OK
MESSAGE('SetHttpGET failed: '& curl.StrError(res), 'libcurl', ICON:Exclamation)
END
END
IF Send:CustomRequest
res = CURL.SetCustomRequest(Send:CustomRequest)
IF res <> CURLE_OK
MESSAGE('SetCustomRequest failed: '& curl.StrError(res), 'libcurl', ICON:Exclamation)
END
END
res = curl.SetUserPwd(Send:User, Send:Pwd)
IF res <> CURLE_OK
MESSAGE('SetUserPwd failed: '& curl.StrError(res), 'libcurl', ICON:Exclamation)
END
IF SSLInfo:bUseSSL
res = curl.SetSSLVerifyHost(SSLInfo:bVerifyHost)
IF res <> CURLE_OK
MESSAGE('SetSSLVerifyHost failed: '& curl.StrError(res), 'libcurl', ICON:Exclamation)
END
res = curl.SetSSLVerifyPeer(SSLInfo:bVerifyPeer)
IF res <> CURLE_OK
MESSAGE('SetSSLVerifyPeer failed: '& curl.StrError(res), 'libcurl', ICON:Exclamation)
END
res = curl.SetSSLVersion(SSLInfo:Version)
IF res <> CURLE_OK
MESSAGE('SetSSLVersion failed: '& curl.StrError(res), 'libcurl', ICON:Exclamation)
END
IF SSLInfo:Certificate
res = curl.SetCAInfo(SSLInfo:Certificate)
IF res <> CURLE_OK
MESSAGE('SetCAInfo failed: '& curl.StrError(res), 'libcurl', ICON:Exclamation)
END
END
END
if Send:CustomRequest='POST'
Send:PostParams ='{{' |
& '"apikey”: "SL-0a9e160bfec9-f69a94c16fa7-7634627146c0”,' |
& '"p_id”: "105”,' |
& '"p_orgjed”: "10”,' |
& '"p_pan”: "00750000000011”,' |
& '"p_user_id”: "100”,' |
& '"p_iznos_racuna”: 50,' |
& '"p_iznos_bez_ak”: 0,' |
& '"p_iznos_placen_bp”: 1,' |
& '"p_iznos_placen_pp”: 5,' |
& '"p_komentar”: "”,' |
& '"stavke”: [' |
& '{{' |
& '"rbr”: 1,' |
& '"artikal”: "14”,' |
& '"kolicina”: 1,' |
& '"popust”: 0,' |
& '"iznosMP”: 50' |
& '}' |
& '],' |
& ' " vauceri”: {{ "1”:{{"kod”:"000001002005978451”} }' |
& '}'
!message(Send:PostParams,,,,,2)
end
Send:Url='https://myspotlight.app/api/int/insert-transaction-v2'
IF bSaveServerResponseToFile
res = curl.SendRequest(Send:Url, Send:PostParams, Send:Filename)
ELSE
res = curl.SendRequest(Send:Url, Send:PostParams, respBuffer)
END
IF res = CURLE_OK
IF bSaveServerResponseToFile
?txtHttpResponse{PROP:Text} = 'Response saved to file: '&CLIP(Send:Filename)
DISPLAY(?txtHttpResponse)
SELECT(?txtHttpResponse)
ELSE
?txtHttpResponse{PROP:Text} = CLIP(respBuffer.Str())
DISPLAY(?txtHttpResponse)
SELECT(?txtHttpResponse)
END
ELSIF res = -1
MESSAGE('Cannot open local file', 'libcurl', ICON:Exclamation)
ELSE
SETCLIPBOARD('SendRequest failed: '& curl.StrError(res))
MESSAGE('SendRequest failed: '& curl.StrError(res), 'libcurl', ICON:Exclamation)
END
DisposeDynStr(respBuffer)