I am attempting to access the Numara Footprints web services API from google apps script. There is no wsdl for the web service, but the methods are well documented. All of the examples of using Google Apps Script Soap Service assume the existence of a wsdl file, which makes it a non-starter for my purposes. So I am trying to use UrlFetchApp instead. By using the sample php code that Numara Footprints provides, I established what the request should look like, and wrote the following code in google apps script:
function sendHttpPost() {
var payload= '<?xml version="1.0" encoding="utf-8"?>' +
'<SOAP-ENV:Envelope'+
'xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"'+
'xmlns:ns1="MRWebServices"'+
'xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"' +
'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'+
'<SOAP-ENV:Body>'+
'<ns1:MRWebServices__search>'+
'<param0 xsi:type="xsd:string">ACCOUNT NAME</param0>'+
'<param1 xsi:type="xsd:string">PASSWORD</param1>'+
'<param2 xsi:type="xsd:string"></param2>'+
'<param3 xsi:type="xsd:string">'+
"SELECT * from MASTER1 where mrid='16888'</param3>"+
'</ns1:MRWebServices__search>'+
'</SOAP-ENV:Body>'+
'</SOAP-ENV:Envelope>';
var headers =
{
"SOAPAction" :encodeURIComponent("MRWebServices#MRWebServices__search")
};
var options =
{
"contentType": "text/xml; charset=utf-8",
"method" : "post",
"headers" : headers,
"payload" : payload
};
UrlFetchApp.fetch("http://FOOTPRINTS SERVER/MRcgi/MRWebServices.pl", options);
}
This code contacts the server successfully and gets the following error message returned:
Request failed for http://FOOTPRINTS SERVER/MRcgi/MRWebServices.pl
returned code 500. Server response:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Application failed during request deserialization:
not well-formed (invalid token) at line 1, column 70, byte 70 at
C:/FootPrints/bin/Perl/lib/XML/Parser.pm line 187 </faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope> (line 40)
I don't know of any way to get more detailed error messages, and I don't know what the problem is. The xml that I am sending is copied directly from the PHP code that works perfectly.
I'm wondering if anyone either:
can see a problem with the google apps script code above or
can tell me how to use the Google Apps Script soap service when I don't have a wsdl file or
knows of a way to get a web service to return more error details.
Thanks in advance. I've looked everywhere that I can think of but not found an answer.
The payload var in the above code needed spaces between the XML elements. Corrected code (note spaces at the end of each line):
var payload= '<?xml version="1.0" encoding="utf-8"?> ' +
'<SOAP-ENV:Envelope '+
'xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '+
'xmlns:ns1="MRWebServices" '+
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" ' +
'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> '+
'<SOAP-ENV:Body> '+
'<ns1:MRWebServices__search> '+
'<param0 xsi:type="xsd:string">ACCOUNT NAME</param0> '+
'<param1 xsi:type="xsd:string">PASSWORD</param1> '+
'<param2 xsi:type="xsd:string"></param2> '+
'<param3 xsi:type="xsd:string"> '+
"SELECT * from MASTER22 where mrid='16888'</param3> "+
'</ns1:MRWebServices__search> '+
'</SOAP-ENV:Body> '+
'</SOAP-ENV:Envelope>';
Also, in the headers, I did not need to use encodeURIComponent(). Corrected code:
var headers =
{
"SOAPAction" :"MRWebServices#MRWebServices__search"
};
Related
Below scenario bringing in me proper SOAP body but I'm not able to extract it's values using xpath expression
The path expression /*/soap:Body/m:NumberToDollarsResponse/m:NumberToDollarsResult/text() I have formed using this website
https://codebeautify.org/Xpath-Tester
val httpConf = http.baseUrl("https://www.dataaccess.com")
val headerXml = Map("Keep-Alive" -> "115", "Content-Type" -> "application/soap+xml; charset=utf-8")
val soapXmlScn = scenario("make First Soap Call")
.exec(
http("Soap API Call With XML")
.post("/webservicesserver/numberconversion.wso")
.headers(headerXml)
.body(StringBody("""<?xml version="1.0" encoding="utf-8"?>
<soap20:Envelope xmlns:soap20="http://www.w3.org/2003/05/soap-envelope">
<soap20:Body>
<NumberToDollars xmlns="http://www.dataaccess.com/webservicesserver/">
<dNum>45</dNum>
</NumberToDollars>
</soap20:Body>
</soap20:Envelope>"""))
.check(status.is(200))
.check(xpath("""//*/soap:Body/m:NumberToDollarsResponse/m:NumberToDollarsResult/text()""").saveAs("doller_value" ))
)
.exec {
session =>
println("doller value >>>> " + session("doller_value").as[String].toString)
session
}
Response body is
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<m:NumberToDollarsResponse xmlns:m="http://www.dataaccess.com/webservicesserver/">
<m:NumberToDollarsResult>forty five dollars</m:NumberToDollarsResult>
</m:NumberToDollarsResponse>
</soap:Body>
</soap:Envelope>
The error shown on console is
12:22:16.880 [ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - 'hook-1' crashed with 'j.u.NoSuchElementException: No attribute named 'doller_value' is defined', forwarding to the next one
namespace List needs to be provided to your xpath check as below and my request working fine. Those namespace URLs are mentioned in your SOAP response xml only
.check(xpath("""//soap:Envelope/soap:Body/m:NumberToDollarsResponse/m:NumberToDollarsResult/text()""", List("soap" -> "http://www.w3.org/2003/05/soap-envelope", "m" -> "http://www.dataaccess.com/webservicesserver/")).findAll.saveAs("doller_value" ))
Below is my working Google apps script SOAP API envelop call. It works to connect ok and as you can see below it returns a response, but my response is encoded. How/where to add a bit to do a Base64decode to see the XML that is returned instead of the string of characters? I am totally new to SOAP API and still a newbie to apps script too. Thanks!
function getData() {
var webservice = ‘https://someplace.com/services/stuff/’;
var xml = '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://someurlhere.com">'
+ '<soapenv:Header/>'
+ '<soapenv:Body>'
+ '<ser:getReportXML soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> '
+ '<in0 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">' + userid + '</in0> '
+ '<in1 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">' + password + '</in1> '
+ '<in2 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">' + startDate + '</in2> '
+ '<in3 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">' + endDate + '</in3> '
+ '</ser:getReportXML> '
+ '</soapenv:Body>'
+' </soapenv:Envelope>'
var options = {
headers: {"SOAPAction" :"https://someplace.com/services/stuff/"},
method: "post",
contentType: "text/xml",
payload: xml,
muteHttpExceptions: true,
};
var serviceaddress = webservice;
var response = UrlFetchApp.fetch(serviceaddress, options);
Logger.log(response);
};
It returns an encoded string in the response, but I want to see the actual XML results:
[19-01-31 11:46:02:122 PST] <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ns1:getReportXMLResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1=" http://someurlhere.com "><getReportXMLReturn xsi:type="soapenc:base64Binary" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">WMui8xyxcPQXmZgSerdPd94bwWxGsAMgdmVyc2lvbj0iFRxlTSerdgiPz4NCg0KPQFET0NUW
I am trying to get the response output to look like xml and not a string of characters
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE ETRANS PUBLIC "-//Something//ethings DTD//EN" "https://www.url.com/dtd/ethings_1_0.dtd">
<ETRANS>
<USER ID="AABB1122" USER_NAME="Smith, John" DATE="2019-02-01 09:41:45" DEPT_ID=""/>
</ETRANS>
So I figured out that my response does have the encoded body of the XML, but it also has all these extra bits in the response before the actual encoded data, so the decoder fails as it doesn't know what to do with this bit shown here at the beginning of the response
[19-01-31 11:46:02:122 PST] <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><ns1:getReportXMLResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1=" http://someurlhere.com "><getReportXMLReturn xsi:type="soapenc:base64Binary" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
and a few more bits at the bottom that are like some closing of the above bits. Is there something I need to pass in my request to have the SOAP request only return the character string and not these extra bits that look like it is putting the "envelope" around the encoded data it is sending back?
I finally figured this out. I don't know if there is a "better" way to do this, but if you see what I did maybe you might share that "better" way. So I added the "NEW BIT" lines below. I had to get rid of the SOAP Envelop in order to decode the base64 bit. The only way I could figure out in Google Apps Script was to save the response as a file as that seemed to "magically" take the SOAP away. So then I had to get the base64 bit that was left that was in the MyTestFile file I created into a text string and decode/convert that and it created the xml I was looking for. I hope this can help someone else out.
function getData() {
var webservice = ‘https://someplace.com/services/stuff/’;
var newDocName = 'MyTestFile'
var xml = '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://someurlhere.com">'
+ '<soapenv:Header/>'
+ '<soapenv:Body>'
+ '<ser:getReportXML soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> '
+ '<in0 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">' + userid + '</in0> '
+ '<in1 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">' + password + '</in1> '
+ '<in2 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">' + startDate + '</in2> '
+ '<in3 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">' + endDate + '</in3> '
+ '</ser:getReportXML> '
+ '</soapenv:Body>'
+' </soapenv:Envelope>'
var options = {
headers: {"SOAPAction" :""},
method: "post",
contentType: "text/xml",
payload: xml,
muteHttpExceptions: true,
};
var serviceaddress = webservice;
var response = UrlFetchApp.fetch(serviceaddress, options).getContentText();
//Logger.log(response);
//NEW BIT BEGINS HERE THAT DECODED THE RESPONSE
var blob = DriveApp.createFile('dummy',response, 'text/html').getBlob();
var resource = {
title: newDocName,
convert: true,
mimeType: 'application/vnd.google-apps.file'
};
var file = Drive.Files.insert(resource,blob);
var doc = DocumentApp.openById(file.id);
var text = doc.getBody().getText();
var decoded = Utilities.base64Decode(text,Utilities.Charset.UTF_8); // This was a byte array
var decodedstr = Utilities.newBlob(decoded).getDataAsString() // This was the xml I was looking for
Logger.log(decodedstr);
//NEW BIT ENDS HERE
};
I'm trying to request a line from Azure Table Storage using the REST API and C++, but always got the following error:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<cod_e>JsonFormatNotSupported</cod_e>
<message xml:lang="en-US">JSON format is not supported.
RequestId:0ccb3b9b-0002-0029-3389-0d2fa1000000
Time:2016-09-13T06:39:13.3155742Z</message>
</error>
Here is my request:
GET https://<myaccount>.table.core.windows.net/<mytable>(PartitionKey='<mypartition>',RowKey='<myrow>')?<sharedsignature>
Here how I fill request headers, as from https://msdn.microsoft.com/en-us/library/dd179428.aspx:
std::string sharedAccessSignature("<sharedsignature>");
std::string dateTime(GetDateTime());
std::string stringToSign(dateTime + "\n/" + account + "/" + "<mytable>");
std::string request("(PartitionKey='<mypartition>',RowKey='<myrow>')");
stringToSign += request;
std::string signatureString(HMACSHA256(stringToSign, sharedAccessSignature));
headers["Authorization"] = "SharedKeyLite " + account + ":" + signatureString;
headers["DataServiceVersion"] = "3.0;NetFx";
headers["MaxDataServiceVersion"] = "3.0;NetFx";
headers["x-ms-version"] = "2015-12-11";
headers["x-ms-date"] = dateTime;
headers["Accept"] = "application/json;odata=verbose";
headers["Accept-Charset"] = "UTF-8";
The table exists and is not empty.
Please advise what's wrong?
Update 1
Removing sharedsignature from request, i.e. GET https://<myaccount>.table.core.windows.net/<mytable>(PartitionKey='<mypartition>',RowKey='<myrow>') leads to the same result.
Removing Authorization header from the request leads to the same result too.
Update 2
Putting https://<myaccount>.table.core.windows.net/<mytable>(PartitionKey='<mypartition>',RowKey='<myrow>')?<sharedsignature> in a browser produces a valid response, but in Atom format.
<?xml version="1.0" encoding="utf-8"?>
<entry
xml:base="https://<myaccount>.table.core.windows.net/"
xmlns="http://www.w3.org/2005/Atom"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
m:etag="W/"datetime'2016-09-13T05%3A29%3A51.211538Z'"">
<id>https://<myaccount>.table.core.windows.net/<mytable> (PartitionKey='<mypartition>',RowKey='<myrow>')</id>
<category term="<myaccount>.<mytable>" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" title="<mytable>" href="<mytable> (PartitionKey='<mypartition>',RowKey='<myrow>')" />
<title />
<updated>2016-09-13T11:25:19Z</updated>
<author><name /></author>
<content type="application/xml">
<m:properties>
<d:PartitionKey><mypartition></d:PartitionKey>
<d:RowKey><myrow></d:RowKey>
<d:Timestamp m:type="Edm.DateTime">2016-09-13T05:29:51.211538Z</d:Timestamp>
<d:Score m:type="Edm.Int32">1050</d:Score>
</m:properties>
</content>
</entry>
Update 3
Investigation situation using curl I found that adding Accept: application/json;odata=fullmetadata to the request headers leads to the error above. Default Accept */* in headers produces valid Atom response.
Finally, got it!
The issue was in my shared signature.
While looking at it I found sv=2012-02-12 part, and assumed, that it means API version. The version, before JSON support was introduced! I created a new shared signature and finally got JSON with the following curl command.
curl -v -H "Accept: application/json;odata=nometadata" -H "x-ms-version: 2015-12-11" "https://<myaccount>.table.core.windows.net/<mytable>(PartitionKey='<mypartition>',RowKey='<myrow>')?<mysharedsignature>"
So, for everyone, who face the same issue in the future: please check your signature first!
Im following this link
i have successfully got this result:
{
"errors": null,
"response": {
"jobId": "628cf1c0cd1c5d8a6c1765f618b7a0be34c50bc1564618",
"status": "submitted",
"jobResponse": null
}
}
ant tried GET call to check the status of the job , exactly as they are asking
https://api.admanager.yahoo.com/v1/rest/reports/custom/628cf1c0cd1c5d8a6c1765f618b7a0be34c50bc1564618?access_token=&advertiserId=21
but i get an error massage :
<?xml version="1.0" encoding="UTF-8"?>
-
Please provide valid credentials. OAuth oauth_problem="unable_to_determine_oauth_type", realm="yahooapis.com"
what am i doing wrong ?
i have even tried adding the access token
Yahoo API wasn't that precise beside the fact they had some system maintenance
this is how the url for testing if job has finished:
String urlToCheckIfDownloadReady = "https://api.admanager.yahoo.com/v1/rest/reports/custom/" + jobId + "?access_token=" + refreshToken + "&advertiserId=" + config.mccCustomerId;
if status = completed
Get from the Json response the jobResponse and than download it
I'm attempting to call SOAP Web-Service in hybrid app. How should I form SOAP message correctly if the back-end service displays the next error in log:
Caused by: com.ibm.websphere.security.WSSecurityException: Exception
org.apache.axis2.AxisFault: CWWSS7509W: The received SOAP request
message is rejected becasue it does not correctly specify SOAP action
and WS-Addressing action while there is at least one PolicySet
attachment at operation level of the
TestServiceService.TestServicePort service. ocurred while running
action:
com.ibm.ws.wssecurity.handler.WSSecurityConsumerHandler$1#9b5addf6 at
com.ibm.ws.security.context.ContextImpl.runWith(ContextImpl.java:394)
at
com.ibm.ws.wssecurity.platform.websphere.auth.WSSContextImpl.runWith(WSSContextImpl.java:65)
... 35 more
This is content of js file in adapter
function getToken(){
var token = WL.Server.getActiveUser().attributes.LtpaToken;
var fulltoken = "LtpaToken2=" + token;
return fulltoken;
}
function callService(){
WL.Logger.warn("INSIDE callService "+getToken());
var path="checkauth/TestServiceService";
var request=
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:q0="http://provider.ws/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<q0:callService />
</soapenv:Body>
</soapenv:Envelope>;
var input = {
method : 'post',
returnedContentType : 'xml',
path : path,
body: {
content: request.toString(),
contentType: 'text/xml; charset=utf-8',
},
headers: {"Cookie": getToken()}
};
var result= WL.Server.invokeHttp(input);
return result;
}
This is SOAP Envelope which was displayed via TCP/IP Monitor:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<s:Security xmlns:s="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:w2="http://www.ibm.com/websphere/appserver/tokentype" soapenv:mustUnderstand="1">
<u:Timestamp>
<u:Created>2015-08-10T13:18:56.644Z</u:Created>
</u:Timestamp>
<s:BinarySecurityToken ValueType="w2:LTPAv2" u:Id="ltpa_20">dt8G5gZ9PpZ/Ea5oXr6EQd8dpmfXKiqeXiShPlpSWntK59hUzyoDNX9TKq1nFLfxUEJyJdjMxoG7EVxw8Q1zhyZdYhTXnsMkNVqScvSsPpX7ln/ad+/WAHqaaFymD8XtVEsjOlezQDarPaUmnKAQRUSrLkRnL5B1MoCclTe129Oojg8o+hACgDKjuvPnvL8jaf45wNiou6Il5ZOayBcoHpNehI7i2hADa4fTKzX/T69OPnsZOyWYrNosdezNd24b61vs85k2YK26rLTp5dkEp8f3mwKZBwOOK4z1wQdiAXJf6kQvzR22SfFitbJA5MStlBcovHAvB5T+J5Ip80/kI5BPa2ogoufd9HZAdKTNII8cHpHBN2Ub/+atzg1L7EhIWuzO1BPI62KoU/hPqAHn3uGCGrbIILesKx0TPvlgmU4Bg54H9prC0I8hgXbO1HLuz4M5DNE5ASFbH0W3LJ/UU7BGXJs6iJmfAfJtQ+ip5ZFHlLItZA+ca2LkVWmyD/xKVxyxHE1uDz8zV/CfV9Km0T+8FTA0Cfi/PIb5KiAagdrmqtw6GuJDbSCsC3sdh21G/cA3Y0p/f+rhDw8m/e17y1cEuq9HOBharwn7ET3wO30V4D4rGoLhd4QsN6X1z89gZmZVaI6J9urpPAEiSndmyQ==</s:BinarySecurityToken>
</s:Security>
<wsa:To>http://X.X.X.X:9082/checkauth/TestServiceService</wsa:To>
<wsa:MessageID>urn:uuid:5d1f8656-5550-40d2-9f39-c58f57279489</wsa:MessageID>
<wsa:Action>http://provider.ws/TestServiceDelegate/callServiceRequest</wsa:Action>
</soapenv:Header>
<soapenv:Body>
<ns2:callService xmlns:ns2="http://provider.ws/"/>
</soapenv:Body></soapenv:Envelope>
The body consists of a single line, and this makes the scenario a peculiar one, as well as raises a question is this is meant to work at all.
I can suggest two things:
You can attempt to parse your WSDL file with the SOAPUI application; it should show you how the SOAP envelope is supposed to look like
Use the Service Discovery feature in MobileFirst Studio that can generate the adapter for you with a ready SOAP envelope. Read more how to use this feature, here: http://www-01.ibm.com/support/knowledgecenter/SSHS8R_7.0.0/com.ibm.worklight.dev.doc/dev/c_using_service_discovery_wizard_to_explore_backend-services.html