Friday 2 June 2017

API whit nodeJS

I have an application in NodeJS. I'm trying to make a request to an external API that I do not have power to change anything, just use. It is an API in SOAP HTTP. I'm using the easysoap module, but when I invoke the "call" method, it returns ReferenceError: the name is not defined.

var easysoap = require('easysoap');

    // define soap params
    var params = {
        host   : ‘hostUrl’,
        path   : ‘/path/method.Services’,
        wsdl   : ‘/path/method.Services?wsdl',

        // set soap headers
        headers: [{
            'Content-Type'     : 'text/xml'
            'encoding'    : 'utf-8',
        }]
    }

    /*
     * create the client
     */
    var soapClient = easysoap.createClient(params);


    /*
     * get all available functions
     */
    soapClient.getAllFunctions().then((functionArray) => {
        /*
         * call soap method
         */
         console.log(functionArray);
        soapClient.call({
            method    : functionArray[2],
            attributes: {
                'xmlns': ‘host’
            },
            params    : {

                }
            }
        })
        .then((callResponse) => {
            console.log(callResponse.data); // response data as json
            console.log(callResponse.body); // response body
            console.log(callResponse.header);  //response header
        })
        .catch((err) => {
            throw new Error(err);
        });
    }).catch((err) => {
        throw new Error(err);
    });



via Erick Marques Pisco

No comments:

Post a Comment