INVALID SESSION VBA
mukeshpiplai opened this issue · 3 comments
I am using the following code for hashpowerEarnings results from API In Excel with VBA, but it shows an INVALID SESSION error
Private strURL, strQuery, apiKey, apiSecret, urlSignature, OrgID, nTime, nNonce, xAuth As String
Sub getAPIData()
Dim endpoint As String
Dim encodedURLLink As String
Dim urlroot As String
Dim pth As String
Dim spaceS As String
urlroot = "https://api2.nicehash.com"
pth = "/main/api/v2/accounting/hashpowerEarnings/BTC"
apiKey = "XXXX"
apiSecret = "XXXX"
OrgID = "XXXX"
nTime = nichhashTime
nNonce = generateNonce
endpoint = apiKey + nTime + nNonce + OrgID + "GET" + pth
strURL = urlroot & pth
xAuth = apiKey & ":" & HexHash(endpoint, apiSecret, "SHA256")
Debug.Print GetHttpResponse()
End Sub
Function GetHttpResponse() As String
Dim objHTTP: Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
With objHTTP
.Open "GET", strURL, False
.setrequestheader "X-Time", Str(nTime)
.setrequestheader "X-Nonce", nNonce
.setrequestheader "X-Organization-Id", OrgID
.setrequestheader "X-Request-Id", generateNonce
.setrequestheader "X-Auth", xAuth
.send
GetHttpResponse = .responseText
End With
Set objHTTP = Nothing
End Function
Function nichhashTime() As String
Dim strTime As String
Dim xhr1: Set xhr1 = CreateObject("WinHttp.WinHttpRequest.5.1")
With xhr1
.Open "GET", "https://api2.nicehash.com/api/v2/time"
.send
.waitForResponse
strTime = .responseText
End With
nichhashTime = Mid(strTime, 15, 13)
End Function
API reply is following-
{"error_id":"dc7a58bc-805c-4fc7-990d-2741dd6d5269","errors":[{"code":2000,"message":"Invalid `session"}]}
hash seems not to be calculated OK ... u can try to verify your generated auth hash with api calls within documentation
just click "Try it out"
https://www.nicehash.com/docs/rest/get-main-api-v2-accounting-hashpowerEarnings-currency
I couldn't found the hash issue in my code because the same hash function working well for another API platform.
hash seems not to be calculated OK ... u can try to verify your generated auth hash with api calls within documentation
just click "Try it out"https://www.nicehash.com/docs/rest/get-main-api-v2-accounting-hashpowerEarnings-currency
I tried with all but not working.. can you tell me what's wrong in above code to generated hash