Skip to main content
Participant
September 26, 2023
Question

API Auth doesn't work with SuiteScript but Works in Local Nodejs Script

  • September 26, 2023
  • 1 reply
  • 455 views

Hello - I am attempting to create an agreement for signature based on some form changes that happen in NetSuite. When I run the script to send the users info to Adobe Acrobat I get this odd response which looks like html for a login page. My credentials work fine in my nodejs script and im able to create the agreement but when I convert that to work in NetSuite it does not. 

Bad response -

<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- suppressReferer attribute is used to disable referer policy(meta tag) in case of any exceptions like logging into sign server etc -->
<!-- if we are in a document cloud login, we also use full screen -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <meta name="referrer" content="strict-origin-when-cross-origin" />
    <title>Adobe Acrobat Sign</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="robots" content="noindex" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="description"
        content="Free e-signature Site. The fastest way to get your documents signed. From Acrobat Sign, a free document process management service" />
    <meta name="keywords" content="e-signature, signatures, email signatures, fax signatures, document management" />
    <meta http-equiv="imagetoolbar" content="no" />
    <meta http-equiv="imagetoolbar" content="false" />
    <meta name="viewport" content="initial-scale=1">
    <meta name="logging_uri" content="https://dc-api.adobe.io" />
    <meta name="server_env" content="prod" />
    <script
        nonce="1aysg9i6ta9y43zld84h4scra"> (function (d) {
                var config = {
                    kitId: 'pfu1huz', scriptTimeout: 3000, async: true, // Fix for DCES-4213971: While Typekit fonts are loading, html tag gets wf-loading class that sets // it and all its children visibility:hidden. So when coachmark is initialized before this class // is removed from html tag, there is no first tabbable field(they are all hidden) that coachmark should point to // and it is not shown. active: function () { if (typeof App !== 'undefined' && typeof App.EventBus !== 'undefined') { App.EventBus.trigger('typekit.loaded', {active:true}); } }, inactive: function () { if (typeof App !== 'undefined' && typeof App.EventBus !== 'undefined') { App.EventBus.trigger('typekit.loaded', {active:false}); } } }, h=d.documentElement,t=setTimeout(function(){h.className=h.className.replace(/\bwf-loading\b/g,"")+" wf-inactive";},config.scriptTimeout),tk=d.createElement("script"),f=false,s=d.getElementsByTagName("script")[0],a;h.className+=" wf-loading";tk.src='https://use.typekit.net/'+config.kitId+'.js';tk.async=true;tk.onload=tk.onreadystatechange=function(){a=this.readyState;if(f||a&&a!="complete"&&a!="loaded")return;f=true;clearTimeout(t);try{Typekit.load(config)}catch(e){}};s.parentNode.insertBefore(tk,s) })(document); </script>
    <script nonce="1aysg9i6ta9y43zld84h4scra"
        type="text/javascript"> disableNiceFileInput=false; enablePlaceHolderPlugin=false; var dwrConfig = { cookieAttributes: "; SameSite=None; secure" }; </script>
    <script nonce="1aysg9i6ta9y43zld84h4scra" type="text/javascript"> (function () { var cookieTest = navigator.cookieEnabled; var isChromiumBased = /Chrom(e|ium)/.test(navigator.userAgent) && !/Edge\/1/.test(navigator.userAgent); if (cookieTest && !isChromiumBased) { document.cookie = "cooki

 nodejs script that works

const axios = require('axios');

const apiKey = '########################';
const baseUrl = 'https://api.na4.adobesign.com/api/rest/v6';

// Use Library Document ID (template ID) instead of Transient Document ID
const libraryDocumentId = '###############';

async function createAgreement() {
  try {
    const agreementData = {
      "fileInfos": [{
        "libraryDocumentId": libraryDocumentId
      }],
      "name": "Credit Application",
      "participantSetsInfo": [{
        "memberInfos": [{
          "email": "test@gmail.com"
        }],
        "order": 1,
        "role": "SIGNER"
      }],
      "signatureType": "ESIGN",
      "state": "IN_PROCESS"
    };

    const response = await axios.post(`${baseUrl}/agreements`, agreementData, {
      headers: {
        'Authorization': `Bearer ${apiKey}`,
        'Content-Type': 'application/json',
      },
    });

    console.log('Agreement ID:', response.data.id);
  } catch (error) {
    console.error('Error creating agreement:', error.response ? error.response.data : error.message);
  }
}

createAgreement();

 

SuiteScript

 var customerEmail = newRecord.getValue('email');
                    var businessName = newRecord.getValue('companyname');

                    // URL and API Key for Adobe Sign API
                    var adobeApiUrl = 'https://api.na4.adobesign.com/api/rest/v6/agreements';
                    var apiKey = '#############';
                    var libraryDocumentId = '###########';

                    // Adobe Sign Agreement Data
                    var adobeSignData = {
                        "fileInfos": [{
                            "libraryDocumentId": libraryDocumentId
                        }],
                        "name": "Mustang Survival Credit Application",
                        "participantSetsInfo": [{
                            "memberInfos": [{
                                "email": customerEmail
                            }],
                            "order": 1,
                            "role": "SIGNER"
                        }],
                        "signatureType": "ESIGN",
                        "state": "IN_PROCESS"
                    };

                    try {
                        var adobeResponse = https.post({
                            url: adobeApiUrl,
                            headers: {
                                "Authorization": "Bearer " + apiKey,
                                "Content-Type": "application/json"
                                
                            },
                            body: JSON.stringify(adobeSignData)
                        });
                        log.debug("Customer Email", customerEmail);
                        log.debug("Adobe Sign API Response", adobeResponse.body);


                    } catch (e) {
                        log.error("Error Sending Document with Adobe Sign", e.toString());
                    }

 

This topic has been closed for replies.

1 reply

Participant
September 27, 2023

SOLVED - I was missing 

"Accept": "application/json"
in my header.