Created
January 16, 2018 11:53
-
-
Save iainplimmer/733cc67664e966d4bc26161d80da4e1e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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