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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,223,885
Messages
6,175,182
Members
452,615
Latest member
bogeys2birdies

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