Reputation: 99
I'm using this lib: https://github.com/vpulim/node-soap, to get data from an API. I have a file caled apiDecoder.ts with the following code:
class NuSoapClient{
public GetNuSoapInfo():string{
var soap = require('soap')
var url = "https://my.url.com/consultNFSe/server.php?wsdl"
var args = {token. :"mysecrettoken",
doc : "000000000",
number : "000000000"
}
soap.CreateClient(url, function(err, client){
client.MyFunction(args, function(err, result){
console.log(result);
});
});
return
}
}
var nf = new NuSoapClient()
nf.GetNuSoapInfo()
console.log(nf)
I get the following error when I compile the code:
" SyntaxError: Unexpected identifier
at Module._compile (internal/modules/cjs/loader.js:895:18)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
at internal/main/run_main_module.js:17:11 "
PS: I was coding the same function in PHP (OO too), there is a missing argument that I didn't get the way to use in TypeScript, the "consultaNFSe" on $res variable. It defines who I'm calling in the API. Here's the working PHP code with Nusoap lib:
$client = new nusoap_client('https://my.url.com/consultNFSe/server.php?wsdl');
$parameters = array('token'=> $results->token,
'cnpj'=> $results->cnpj,
'nrNota'=> $results->nota);
$res = $client->call('consultaNFSe', $parameters);
$contents = file_get_contents("data.php");
$arr = json_decode($res, true);
Any thoughts? I'm stuck at this point.
Upvotes: 1
Views: 6545
Reputation: 855
I sugest you to call all libraries outside class scope, ex:
const soap = require('soap')
class Examp {}
I'm not pretty sure but I think that soap.CreateClient require another not optional parameter (options). So, will be:
soap.CreateClient(url, {}, function(err, client){ //here second parameter
if (err) throw(err);
client.MyFunction(args, function(err, result){
console.log(result);
});
});
I hope it helps you.
Upvotes: 1