Last active
January 15, 2021 17:33
-
-
Save JoaoPedroPP/30a692c531d85303a060648a5a022711 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
const fetch = require('node-fetch'); | |
const getToken = () => { | |
return new Promise((resolve, reject) => { | |
const apikey = 'APIKEY do WML'; | |
fetch(`https://iam.bluemix.net/oidc/token`, { | |
method: 'POST', | |
headers: { | |
"Content-Type": "application/x-www-form-urlencoded", | |
Authorization: "Basic " + btoa("bx:bx") | |
}, | |
body: "apikey=" + apikey + "&grant_type=urn:ibm:params:oauth:grant-type:apikey", | |
json: true | |
}) | |
.then(resp => resp.json()) | |
.then(data => { | |
console.log(data) | |
resolve(data.access_token) | |
}) | |
.catch(err => { | |
console.error(JSON.stringify(err)) | |
reject(err) | |
}) | |
}); | |
const body = { | |
input_data: { | |
fields: ['Variaveis'], | |
values: [['Dados']] | |
} | |
}; | |
getToken() | |
.then(token => { | |
fetch('URL de score do modelo', { | |
method: 'POST', | |
headers: { | |
"Content-Type": "application/json", | |
Authorization: `Bearer ${token}` | |
}, | |
body: JSON.stringify(body), | |
json: true | |
}).then(resp => resp.json()) | |
.then(data => { | |
console.log(JSON.stringify(data)); | |
}) | |
.catch(err_wml => { | |
log.logger('err', JSON.stringify(err_wml)) | |
reject(err_wml) | |
}) | |
}) | |
.catch(error => { | |
console.error(JSON.stringify(error)); | |
reject(error) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment