N/https/clientCertificate Module Script Sample

The following script sample demonstrates how to use the features of the N/https/clientCertificate module.

Send a Secure Post Request to a Remote URL

Important:

This sample uses SuiteScript 2.1. For more information, see SuiteScript 2.1.

The following sample sends a secure post request to a remote URL.

Note:

This sample script uses the require function so that you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.

Important:

This sample uses SuiteScript 2.1. For more information, see SuiteScript 2.1.

            /**
 * @NApiVersion 2.1
 */

require(['N/https/clientCertificate'],(cert)=> {
    // Set the URL
    const url = "https://nfe.fazenda.sp.gov.br/ws/cadconsultacadastro4.asmx";

    let data = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\"><soapenv:Body><ns1:nfeDadosMsg xmlns:ns1=\"http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro4\"><ConsCad xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao=\"2.00\"><infCons><xServ>CONS-CAD</xServ><UF>SP</UF><CNPJ>47508411000156</CNPJ></infCons> </ConsCad></ns1:nfeDadosMsg></soapenv:Body></soapenv:Envelope>";

    const key = "custcertificate1";

    let headers = {
        "Content-Type": "application/soap+xml"
         };

    let response = cert.post({
        url: url,
        certId: key,
        body: data,
        headers: headers
    });
}) 

          

General Notices