Ask a Question
Back to All

Node.js Snipped for Axios

Can someone edit the - Node.js - "API for custom short URLs - Code snippet", that I can use it with axios?

let request = require("request");
let linkRequest = {
destination: "https://www.youtube.com/channel/UCHK4HD0ltu1-I212icLPt3g",
domain: { fullName: "rebrand.ly" }
//, slashtag: "A_NEW_SLASHTAG"
//, title: "Rebrandly YouTube channel"

let requestHeaders = {
"Content-Type": "application/json",
"apikey": "YOUR_API_KEY",
"workspace": "YOUR_WORKSPACE_ID"

uri: "https://api.rebrandly.com/v1/links",
method: "POST",
body: JSON.stringify(linkRequest),
headers: requestHeaders
}, (err, response, body) => {
let link = JSON.parse(body);
console.log(Long URL was ${link.destination}, short URL is ${link.shortUrl});