Since the request
module that other answers use has been deprecated, may I suggest switching to node-fetch
:
const fetch = require("node-fetch")
const url = "https://www.googleapis.com/urlshortener/v1/url"
const payload = { longUrl: "http://www.google.com/" }
const res = await fetch(url, {
method: "post",
body: JSON.stringify(payload),
headers: { "Content-Type": "application/json" },
})
const { id } = await res.json()