Skip to content
Advertisement

How to add settings on a post request using JavaScript

I am currently codding a website which will create a paste.ee document.

I fond some answers to the question “How to send a post request”

but I can’t figure out a way to use the API settings in the API.

The API documentation : https://pastee.github.io/docs/

My code so far:

<html>
<body>
<script>
var request = new XMLHttpRequest();

request.open("POST", "https://api.paste.ee/v1/pastes", true);

request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

request.send("X-Auth-Token: mytoken");
</script>
</body>
</html>

If it’s possible I would like to stay with JavaScript so I don’t have to run PHP or python.

Advertisement

Answer

Just read carefully the API Docs. You need to specify the authentication token in the header like so:

var request = new XMLHttpRequest();

request.open("POST", "https://api.paste.ee/v1/pastes", true);

request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.setRequestHeader("X-Auth-Token", "YOUR_TOKEN_GOES_HERE");
request.send('{"description":"test","sections":[{"name":"Section1","syntax":"autodetect","contents":"Testing!"}]}')
Advertisement