cancel
Showing results for 
Search instead for 
Did you mean: 

SOAP API in javascript not working

PremRajani
Collaborator II

SOAP API in javascript doesn't seem to work and what exactly am I doing wrong.

 

     <script type="text/javascript">

        function pageLoad() {
            var request = new XMLHttpRequest();

            request.onreadystatechange = function () {
                if (this.readyState == 4 && this.status == 200) {
                    alert(this.responseText);
                }
                else {
                    //alert(this.status);
                    //alert(this.responseText);
                }
            };

            request.open('POST', 'https://site.com/ws/search.asmx', true);
            request.setRequestHeader('SOAPAction', 'http://archer-tech.com/webservices/ExecuteSearch');
            request.setRequestHeader('Content-type', 'text/xml');
            request.setRequestHeader('Authorization', 'Archer session-id="' + sessionToken + '"');
            //request.setRequestHeader('X-Http-Method-Override', 'GET');

            var searchString = '<SearchReport> ' +
                '<PageSize>100</PageSize> ' +
                '<DisplayFields> ' +
                '<DisplayField>3906</DisplayField> ' +
                '<DisplayField>3907</DisplayField> ' +
                '</DisplayFields> ' +
                '<Criteria> ' +
                '<ModuleCriteria> ' +
                '<Module>84</Module> ' +
                '<IsKeywordModule>false</IsKeywordModule> ' +
                '</ModuleCriteria> ' +
                '<Filter> ' +
                '<Conditions> ' +
                '<TextFilterCondition> ' +
                '<Operator>Contains</Operator> ' +
                '<Field>3896</Field> ' +
                '<Value>12345678</Value> ' +
                '</Filter> ' +
                '</Criteria> ' +
                '</SearchReport>';

 

            var xml='<?xml version="1.0" encoding="utf-8"?> ' +
                '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
                ' xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
                ' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> ' +
                '<soap:Body> ' +
                '<ExecuteSearch xmlns="http://archer-tech.com/webservices/"> ' +
                '<sessionToken>' + sessionToken + '</sessionToken> ' +
                '<searchOptions>' + searchString + '</searchOptions> ' +
                '<pageNumber>1</pageNumber> ' +
                '</ExecuteSearch> ' +
                '</soap:Body> ' +
                '</soap:Envelope>';

            request.send(xml);
        }
    </script>

 

Tried using Res API, but search option isn't enabled. When I fetch using content id it works like a charm.

 

I get 400 bad request.......something to do with searchstring or xml.

1 ACCEPTED SOLUTION
4 REPLIES 4

Hi Jeff,

 

After using CDATA it worked like a charm. Thank you

Hello Prem, Can you please put the code with cdata? Thank you/.

Hello @Jeff , 

Can you please share an example of Archer SOAP API call in Javascript? Also, can we use the same in Archer Javascript Transporter Datafeed to call a report, like we do in A2A datafeed? Just wanted to check this as an alternative to A2A