Skip to content

Instantly share code, notes, and snippets.

@diegopacheco
Last active July 12, 2021 21:13
Show Gist options
  • Save diegopacheco/53eabd7f5fab1bf365e67fdcf176cb02 to your computer and use it in GitHub Desktop.
Save diegopacheco/53eabd7f5fab1bf365e67fdcf176cb02 to your computer and use it in GitHub Desktop.
How to Call WS Soap from Google Cloud Functions
/**
 * Responds to any HTTP request that can provide a "cep" field in the body.
 *
 * @param {!Object} req Cloud Function request context.
 * @param {!Object} res Cloud Function response context.
 */
exports.helloWorld = function helloWorld(req, res) {
    console.log("Using parameter: " + req.body.cep);  
  
    var soap = require('soap');
    var url = 'http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx?WSDL';
    var args = {
                  nCdServico:  "40010",
      			  sCepOrigem:  "94035330",
      			  sCepDestino: req.body.cep
               };
     
    soap.createClient(url, function(err, client) {
       client.CalcPrazo(args, function(err, resoap) {
          res.status(200).send('Success: ' + JSON.stringify(resoap));
       });
    });
 
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment