I was doing some work with the WordPress API, and I had to authenticate to perform a POST request to a website.

The easiest way for me was to use basic authentication.

I was using Axios, so I set the Authorization header to the POST request in this way:

const username = ''

const token = Buffer.from(${username}:${password}, 'utf8').toString('base64')

const url = 'https://...'

axios.post(url, {
'Authorization': Basic \${token}