How to fetch x-csrf-token from Excel using VBA

graphiomaniac

New Member
Joined
Nov 5, 2020
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi Experts,

I am trying to fetch x-csrf-token so that I could use it in subsequent calls. My script looks like below

VBA Code:
Sub ExternalTrigger_Click()
Dim response As String
Set objHTTP = CreateObject("MSXML2.XMLHTTP")

Url = "XXXXXXXXXX"
username1 = "XXXXX"
password1 = "XXXXX"
objHTTP.Open "GET", Url, False, username1, password1
objHTTP.setRequestHeader "x-csrf-token", "fetch"
objHTTP.send ("")
response = objHTTP.GetResponseHeader("x-csrf-token")
MsgBox response

End Sub

However, I am getting an empty message box. I tried to check all response header with getAllResponseHeaders() and I couldn't find x-csrf-token listed. However, it does exist in header as I was able to fetch it using POSTMAN.
Please suggest how to get x-csrf-token from Excel using VBA script.

Regards,
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Two things spring to mind:

(1) is this the correct way of authenticating your credentials? I know that you can pass the username/password details with the .Open method, but with the APIs I used, I've always had to put them in as a request header.
(2) are there no other request headers you might need to provide? User-agent string?

Are there any differences between the data being sent by Postman and by you?
 
Upvote 0

Forum statistics

Threads
1,214,936
Messages
6,122,340
Members
449,079
Latest member
rocketslinger

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top