I'm trying to send POST request to LocalBitcoins API server but I'm only receiving errors (41 and 43) despite the GET request works perfectly even with parameters (arguments).
Sub initrequest()
'this is a POST request with no arguments that results in error
JsonResponse = PrivateLocalBTC("POST", "/api/notifications/mark_as_read/9b9c2b5a16a3/")
'this is a GET request, with "ads=.." parameter, that works
'JsonResponse = PrivateLocalBTC("GET", "/api/ad-get/", "ads=771318")
Debug.Print JsonResponse
End Sub
and there is the HTTP request sub:
Function PrivateLocalBTC(Method As String, endpoint As String, Optional params As String) As String
Dim NonceUnique As String
NonceUnique = CreateNonce(13)
TradeApiSite = "https://localbitcoins.com"
apikey = "..............."
secretkey = "............"
Message = NonceUnique & apikey & endpoint & params
apisign = ComputeHash_C("SHA256", Message, secretkey, "STRHEX")
If params <> "" Then urlparams = "?" & params
Url = TradeApiSite & endpoint & urlparams
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
objHTTP.Open Method, Url, False
objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
objHTTP.setRequestHeader "Apiauth-Key", apikey
objHTTP.setRequestHeader "Apiauth-Nonce", NonceUnique
objHTTP.setRequestHeader "Apiauth-Signature", apisign
objHTTP.Send ("")
objHTTP.waitForResponse
PrivateLocalBTC = objHTTP.ResponseText
Set objHTTP = Nothing
End Function
I've tried many variation putting endpoint, nonce, apikey in the request body at .Send command , urlencoding, but no positive result.
ComputeHash_C, CreateNonce are separate functions. The code is inspired by the great shared work of https://github.com/krijnsent/crypto_vba !
LocalBitcoins API doc is here: https://localbitcoins.com/api-docs/