Fyers API access token code in excel is denying API ID

I have written a basic code in vba, where I am successfully getting the auth code but the access token is not returning successfully.

Sub AuthCode()

Dim wb As ThisWorkbook

Set wb = ThisWorkbook

Dim URL As String

Dim AppID As String

Dim RedirectURI As String

AppID = wb.Sheets("Details").Range("C3").Value

RedirectURI = wb.Sheets("Details").Range("C4").Value

URL = "https://api.fyers.in/api/v2/generate-authcode?client_id=" & AppID & "&redirect_uri=" & RedirectURI & "&response_type=code&state=sample_state"

CreateObject("Wscript.Shell").Run (URL)

End Sub

Sub Generate_token()

Dim wb As ThisWorkbook

Set wb = ThisWorkbook

Dim appIdHash As String

appIdHash = wb.Sheets("Details").Range("C7").Value

Dim AuthCode As String

AuthCode = wb.Sheets("Details").Range("C5").Value

Data = "{""grant_type"":""authorization_code"",""appIdHash"":""" & appIdHash & """,""code"":"""" & AuthCode & """"}"

URL = "https://api.fyers.in/api/v2/validate-authcode"

Dim obj As Object

Set obj = CreateObject("MSXML2.ServerXMLHTTP")

obj.Open "POST", URL, False

obj.SetRequestHeader "Content-type", "application/json"

obj.Send (Data)

Dim result As String

result = obj.ResponseText

Set obj = Nothing

Dim q As String

If InStr(1, result, "error", vbTextCompare) > 0 Then

q = InStr(1, result, "message", vbTextCompare)

MsgBox Mid(result, q + 9)

End If

wb.Sheets("Details").Range("C6").Value = wb.Sheets("Details").Range("C3").Value & ":" & Mid(result, 58, 556)

MsgBox "Access Token Generated."

End Sub

Pls help

1 reply