smartface.io call a web service - smartface.io

I am using smartface.io to call a soap web service. My code is as below. when I call it returns a error says "Server Error" But when I call it from browser it works well.
var requestString =
'' +
'' +
'' +
'' +
'admin#borapay.com' +
'Admin#123456<>' +
'' +
'' +
'';
var getRate = new SMF.Net.WebClient({
URL : "http://172.98.72.148/borapay/WebServices/CustomerServices.asmx",
httpMethod : "POST",
requestHeaders : [
"Content-Type: text/xml;charset=UTF-8",
"SOAPAction: http://tempuri.org/UserLogin"
],
onSyndicationSuccess : function (e) {
},
onServerError : function (e) {
alert("onServerError");
},
requestString : requestString,
responseHandling : SMF.Net.ResponseHandling.forceText,
timeoutInterval : 120
});
getRate.run()

Your request string seems wrong, it should be full envelope like;
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bora="http://bora-pay.com/">
<soapenv:Header/>
<soapenv:Body>
<bora:UserLogin>
<!--Optional:-->
<bora:userName>admin#borapay.com</bora:userName>
<!--Optional:-->
<bora:password>Admin#123456<></bora:password>
</bora:UserLogin>
</soapenv:Body>
</soapenv:Envelope>
But you need to convert that as a Java Script string.

Related

Gatling how to send json body to avoid unmarshal error

I'm trying to send a JSON body to my API using Gatling, but I keep getting error 400 because it cannot unmarshal the body I'm sending:
private val authHeaders = Map(
"Accept" -> "application/json, text/javascript, */*; q=0.01",
"Authorization" -> "Bearer ${access_token}"
)
var requestBody: Body with (Expression[String]) =StringBody("{ \"productId\": " +
product1 + ", \"qty\": "+ 1 +" , \"storeId\": "+ storeId + "}")
var addToCart: ChainBuilder = exec(http("addToCart")
.post(addToCartUrl)
.headers(authHeaders)
.body(requestBody)
.check(bodyString.saveAs("body"))
)
In the Gatling logs I can read that I'm sending this kind of request:
HTTP request:
POST ....
headers:
Accept: application/json, text/javascript, */*; q=0.01
Authorization: Bearer ....
cookie: ROUTE=....
host: .....
content-length: 53
cookies:
ROUTE=...., path=/, secure, HTTPOnly, SameSite=None
body:StringChunksRequestBody{contentType='null', charset=UTF-8, content={ "productId": XXXX, "qty": 1 , "storeId": XXXX}}
I don't think I'm creating the correct body, Is there a way to send only
{ "productId": XXXXX, "qty": 1 , "storeId": XXXXXX} as body?
I might have put the contentType in the wrong way, what is the right order?.
Are you sure product1 and storeId are numbers and not Strings? Otherwise, they must be wrapped with double quotes, which they currently aren't.

How to apply namespace qualifier on parent tag only

I have a soap request that needs to look like this, with the 'user:' qualifier ONLY pertaining to the 'getTopQuestions' tag. Here is what the request SHOULD look like:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<user:getTopQuestions>
<interfaceId>4</interfaceId>
<numberOfQuestions>10</numberOfQuestions>
</user:getTopQuestions>
</soap:Body>
</soap:Envelope>
However, my request looks like this. As you can see, the 'user:' namespace qualifier is attached to the children tags of the parent 'user:getTopQuestions'
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<user:getTopQuestions>
<user:interfaceId>4</user:interfaceId>
<user:numberOfQuestions>10</user:numberOfQuestions>
</user:getTopQuestions>
</soap:Body>
</soap:Envelope>
How do I get the 'user:' namespace qualifier off of the child tags 'interfaceId' and 'numberOfQuestions'?
Here is my request:
$.soap({
url,
method: options.method,
data: options.data || {},
success: soapResponse => {
let responseContent = `${options.method}Response`;
let body = 'Body';
let data = soapResponse.toJSON();
if (data['soap:Body']) {
responseContent = `ns1:${responseContent}`;
body = `soap:${body}`;
}
data = data[body][responseContent];
deferred.resolve(data);
},
error: SOAPResponse => {
deferred.reject(SOAPResponse);
},
namespaceQualifier: "user:",
envAttributes: {
'xmlns:user': '/com/intelliresponse/search/user'
},
SOAPAction: " "
});
Can you remove the ":" from the namespaceQualifier as suggested here
https://github.com/zachofalltrades/jquery.soap
use namespaceQualifier: 'myns', // used as namespace prefix for all
instead of namespaceQualifier: ':myns' //with a colon

Unable to connect HP ALM API via google script

I'm trying to call HPQC API to get some reports but I'm not able to get the QCsession cookie when I call /qcbin/rest/site-session. I successfully authenticated with /qcbin/authentication-point/authenticate but I'm stuck in the next phase.
Not that I can use the API without any trouble with Postman, but my Google script doesn't work.
Here's a look at the call I'm doing :
var headers = { "Accept":"application/xml",
"Content-Type":"application/xml",
"method": "POST",
"headers" : {"Authorization": digestfull },
"muteHttpExceptions": true
};
var resp = UrlFetchApp.fetch(url,headers);
var cookie = resp.getAllHeaders();//['Set-Cookie'];//.split(';')[0].toString();
Logger.log(cookie);
//Get session cookie
param = "/hp/rest/site-session";
var url2 = hpqc + param + api_key;
var payload = "<session-parameters><client-type>REST Client</client-type></session-parameters>";
var headers2 = { "Accept":"application/json",
"Content-Type":"application/xml",
"method": "POST",
"muteHttpExceptions" : true,
"cookie" : cookie,
"body" : payload
};
resp = UrlFetchApp.fetch(url2,headers2);
The first call works fine, but the second gives me the following response :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Error 401 Authentication failed. Browser based integrations - to login append '?login-form-required=y' to the url you tried to access.</title>
</head>
<body><h2>HTTP ERROR 401</h2>
<p>Problem accessing /qcbin/rest/site-session. Reason:
<pre> Authentication failed. Browser based integrations - to login append '?login-form-required=y' to the url you tried to access.</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>
It seems that the cookies aren't correctly sent.
Can you please help me find what is wrong with my code ? I'm sorry if it's too obvious, I'm learning to use google script.
Thank you
I changed the following code
var payload = "<session-parameters><client-type>REST Client</client-type></session-parameters>";
var headers2 = { "Accept":"application/json",
"Content-Type":"application/xml",
"method": "POST",
"muteHttpExceptions" : true,
"cookie" : cookie,
"body" : payload
};
with this and it worked
var payload = "<session-parameters><client-type>REST Client</client-type></session-parameters>";
var headers = {// "accept":"application/json",
//"contentType":"application/json",
"method": "POST",
"muteHttpExceptions" : true,
"headers" : {
"Content-type" : "application/xml",
"Accept" : "application/json",
"Cookie" : cookie
},
"payload" : payload
};
Thank you TheMaster for giving me the hint !!

Resolve email adress from x500 address in EWS

I am using EWS in meteor js app and I am using lather to compose the soap request.
I would like to get all meetings form Exchange, and I need meeting's organiser email address (SMTP), but it always retreive x500 addrress like:
/O=ABCD/OU=EXCHANGE ADMINISTRATIVE GROUP (ABCDEFGH)/CN=RECIPIENTS/CN=ABCD00000"
I have searched for a solution and found this:
NameResolutionCollection coll = service.ResolveName("/O=ABCD/OU=EXCHANGE ADMINISTRATIVE GROUP (ABCDEFGH)/CN=RECIPIENTS/CN=ABCD00000", ResolveNameSearchLocation.DirectoryOnly,true)
But I am not using C#, how can this be done in technology free fashion.
A ResolveName SOAP request should look something like https://msdn.microsoft.com/en-us/library/office/aa563518(v=exchg.150).aspx eg
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2007_SP1" />
</soap:Header>
<soap:Body>
<m:ResolveNames ReturnFullContactData="true" SearchScope="ActiveDirectoryContacts">
<m:UnresolvedEntry>test</m:UnresolvedEntry>
</m:ResolveNames>
</soap:Body>
</soap:Envelope>
So in Lather based on the other example on that page something like
var lather = require('lather');
var resolveName = {
'm:ResolveNames' : {
attributes : [
{ ReturnFullContactData : 'true' },
{ SearchScope : 'ActiveDirectoryContacts' },
],
'm:UnresolvedEntry' : '/O=ABCD/OU=EXCHANGE ADMINISTRATIVE GROUP (ABCDEFGH)/CN=RECIPIENTS/CN=ABCD00000',
},
};
lather.up({
body : resolveName,
headers : {
Authorization : lather.basicAuth(exchangeUserName, exchangePassword),
},
additionalNamespaces : [
'xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"',
'xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"',
],
method : 'POST',
url : 'https://outlook.office365.com/EWS/Exchange.asmx',
}, function(error, res, body) {
...
});
Should work (but maybe some changes are required)
Cheers
Glen

UrlFetchApp Authentication failed Freshbooks

So I am trying to communicate with the freshbooks api by making the sample request detailed on the developers page of freshbooks (http://developers.freshbooks.com/). We are doing token-based authentication as opposed to using OAuth.
I have my code logging the responses to my requests in a spreadsheet. The responses it has been logging are as follows:
<?xml version="1.0" encoding="utf-8"?>
<response xmlns="http://www.freshbooks.com/api/" status="fail">
<error>Authentication failed.</error>
<code>20010</code>
</response>
I have been able to authenticate when using a curl command in console, but not when running the script. Below is the code I used. Left out the logging to spreadsheet part and our specific url and authToken:
// Sample function to call into an API using basic HTTP auth
function freshbooksTest () {
var url = ;
var authToken = ;
var unamepass =authToken+":X";
var digestfull = "Basic "+unamepass;
var payload = '<request method="system.current"></request>';
var options =
{
"method" : "post",
"muteHttpExceptions": true,
"headers" : {"Authorization": digestfull},
"payload" : payload
};
var response = UrlFetchApp.fetch(url, options);
var xml = response.getContentText();
}
I have checked out threads where people are having similar problems, but the solutions were either not applicable to my situation, or have already been tried. Any suggestions are welcome.
Not specifically familiar with UrlFetchApp, but if it doesn't do it for you, you'll need to Base64 encode digestfull before you send it in the header.
Looks like you need to base 64 encode your auth token. Code should look like this:
function freshbooksTest () {
var url = ;
var authToken = ;
var unamepass = authToken+":X";
var digestfull = "Basic "+ Utilities.base64Encode(unamepass);
var payload = '<request method="system.current"></request>';
var options =
{
"method" : "post",
"muteHttpExceptions": true,
"headers" : {"Authorization": digestfull},
"payload" : payload
};
var response = UrlFetchApp.fetch(url, options);
var xml = response.getContentText();
}