Good afternoon
Trying to access API
from App Script
Have accessed other API's in the past & used UrlFetchApp, but does not seem to be supported by this API
Not sure how to use one of the other options
Thanks Simon
I believe your goal is as follows.
From your provided official document, you want to convert the following curl command to Google Apps Script.
curl --location --request POST 'https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1/vehicles' \
--header 'x-api-key: REPLACE WITH YOUR API KEY' \
--header 'Content-Type: application/json' \
--data '{"registrationNumber": "AA19AAA"}'
You have already confirmed that the above curl command worked fine.
In this case, how about the following sample script?
function myFunction() {
const url = "https://driver-vehicle-licensing.api.gov.uk/vehicle-enquiry/v1/vehicles";
const data = { "registrationNumber": "AA19AAA" };
const res = UrlFetchApp.fetch(url, {
method: "post",
headers: { "x-api-key": "REPLACE WITH YOUR API KEY" },
contentType: "application/json",
payload: JSON.stringify(data)
});
console.log(res.getContentText());
}