Send POST request data using VBA

mwl707

New Member
Joined
Jun 5, 2024
Messages
6
Office Version
  1. 2021
Platform
  1. Windows
Any help much appreciated. Im trying to send a request to recieve an access token in VBA.

The suggested format is curl --request POST --url 'Sign in to your account{tenantId}/oauth2/v2.0/token' --header 'content-type: application/x-www-form-urlencoded' --data grant_type=client_credentials --data client_id=CLIENT_ID_HERE --data client_secret=CLIENT_SECRET_HERE --data scope=https://tapi.dvsa.gov.uk/.default

But I want to send this using Excel VBA so far I have this, But I cant get the data to send

API_TOKENURL = ""
API_ID = ""
API_Secret = ""
API_KEY = ""
API_APPLICATION = "application/json"

Set DvlaService = CreateObject("MSXML2.XMLHTTP")

DvlaService.Open "POST", "Sign in to your account", False
DvlaService.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

data = "grant_type=client_credentials"
data = data & "&data-client_id=" & Application.EncodeURL("5683e80b-e549-4721-b1e2-441fa19c9847")
data = data & "&data-client_secret=" & Application.EncodeURL("iZk8Q~-ClQzJ-6NTiOLq6JrkQDiSH3AwlwklYb..")
data = data & "&data-scope=" & Application.EncodeURL("https://tapi.dvsa.gov.uk/.default")

DvlaService.send data

Response = DvlaService.responseText

MsgBox Response

Im still very new to this , so any help or pointers would be great
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,225,738
Messages
6,186,728
Members
453,368
Latest member
positivemind

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