Skip to content

Instantly share code, notes, and snippets.

@iainplimmer
Created January 16, 2018 11:53
Show Gist options
  • Select an option

  • Save iainplimmer/733cc67664e966d4bc26161d80da4e1e to your computer and use it in GitHub Desktop.

Select an option

Save iainplimmer/733cc67664e966d4bc26161d80da4e1e to your computer and use it in GitHub Desktop.
(function(){
// Create the body and master token to send over
const masterToken = 'Sc7K4CpdQ';
const dataToSend = {
username: 'iain@email.com',
sitename: 'website',
token: masterToken
};
// Make the request
fetch("https://www.createtoken.com", {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(dataToSend)
})
.then(function (response) {
if (response.status !== 200) {
onError("Something went wrong", response.status);
}
else {
// Return the body of the response stream as a json object in a promise
return response.json()
}
})
.then(function (data) {
// Unwrap the data from the reponse stream that is returned
console.log(data.domain);
console.log(data.pbTempToken);
})
.catch(function (error) {
onError(error, 0);
})
function onError (error, statusCode) {
console.log(error, statusCode)
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment