2

Does anyone know how to create a request using Netsuite https module attaching a self-signed certificate file(.pem or .pfx extension) to an external Web service?

I want to report invoices to Spain Tax registration entity (SII) automatically using a map/reduce script. I have tested my generated XML into the SII web interface, using POSTMAN and CURL command line and the web service received my request and return an expected XML response. But I am unable to achieve the same results creating the request using N/https module, mainly because I have no idea how to ship that request with the certificate file attached to it. My script fails with a message:

"type":"error.SuiteScriptError","name":"SSS_CONNECTION_TIME_OUT"

Here is the code which I have tried:

var siiURL = 'https://www7.aeat.es/wlpl/SSII-FACT/ws/fe/SiiFactFEV1SOAP';

//get the content of the generated xml
var xml_content = getXMLContent(url);

//get the url of the certificate file that is saved in the NS file cabinet
var certificate = getClientCertificate();
log.audit({ title: 'Certificate File', details: certificate });
var headers = {
    'Content-Type': 'text/xml; charset=utf-8',
    'SOAPAction': 'SuministroLRFacturasEmitidas',
    'local_cert': certificate,
    'passphrase': '****'
};
var SIIresponse = https.post({ url: siiURL, body: xml_content, headers: headers });
log.audit({title: 'Response from SII', details: SIIresponse.code + ' | ' + SIIresponse.body });

The example snippet was taken from a post in PHP: https://es.stackoverflow.com/questions/77233/conectar-con-el-web-service-de-sii-aeat-soap-php

The Spain tax report entity provides a pfx file to authenticate with. For test purposes, I created a PEM file (both cl and key and also a bundle .pem file) using this post: https://es.stackoverflow.com/a/131407/59793

I guess that web service does not expect the certificate file in the header of the request but I have no idea where it should be placed or if there is an appropriate header key for this. Also, I found information about how to save .cert/.pem files to Netsuite but as far as I know, this is for suite commerce:

https://noblue.co.uk/blog/netsuite-tips-installing-an-ssl-certificate-on-suitecommerce

Thanks for any help or comment.

PD. Please excuse any grammar mistake or typo.

elotgamu
  • 43
  • 10

1 Answers1

0

You can try using the N/https/clientCertificate module:

define(['N/https/clientCertificate'], function (cert) {
         ....
         ....
         ....

         var siiURL = 'https://www7.aeat.es/wlpl/SSII-FACT/ws/fe/SiiFactFEV1SOAP';

         //get the content of the generated xml
         var xml_content = getXMLContent(url);

         var key = "certID";

         var headers = {
             'Content-Type': 'text/xml; charset=utf-8', // Use application/soap+xml instead??
             'SOAPAction': 'SuministroLRFacturasEmitidas'
         };

         var SIIresponse = cert.post({
               url: siiURL,
               certId: key,
               body: xml_content,
               headers: headers
         });

         log.audit({title: 'Response from SII', details: SIIresponse.code + ' | ' + SIIresponse.body });

         ....
         ....
         ....
Andrés Andrade
  • 2,213
  • 2
  • 18
  • 23