send request to get API Token
Posted: Thu Sep 12, 2019 12:32 pm
Hi,
i want to send post to request to Api to catch a Token
this is my script and i dont know why i received invalid request from the Api. i guss i wrote something wrong in authoriziation but i am not sure
Thanks for your comments
i want to send post to request to Api to catch a Token
this is my script and i dont know why i received invalid request from the Api. i guss i wrote something wrong in authoriziation but i am not sure
Code: Select all
var myPostData = {};
// Add Values
myPostData['key1'] = "value1";
myPostData['key2'] = "value2";
var myJSON = JSON.stringify(myPostData);
job.log(-1, myJSON );
var theHTTP = new HTTP();
theHTTP.url = 'ApiEndPoint';
theHTTP.authScheme = HTTP.BasicAuth;
theHTTP.user = "username";
theHTTP.password = "password";
theHTTP.authorization = "authorization string";
theHTTP.addHeader( "Content-Type", "application/x-www-form-urlencoded" );
var postBody = new ByteArray( myJSON , "UTF-8" );
theHTTP.setPostData( postBody,"application/x-www-form-urlencoded" );
theHTTP.post();
while( !theHTTP.waitForFinished( 3 ) )
{
job.log( 1, "Refresh token in progress" );
}
var theServerResponse = theHTTP.getServerResponse().toString();
job.log(-1, "Server response: " + theHTTP.getServerResponse().toString("UTF-8"));