Search code examples
next.jsdocusignapi

How to use DocuSign with Next.js 13


I am using Next.js 13 and trying to set up the server within the framework.

I have the below file with src/app/api/docusign

import { NextResponse } from 'next/server'

import docusign from 'docusign-esign';

export async function POST(request: Request) {
  console.log("here")
  const dsApiClient = new docusign.ApiClient();

  return NextResponse.json({ dsApiClient })
}
Import trace for requested module:
./src/app/api/docusign/route.ts
- wait compiling /_error (client and server)...
- error ./node_modules/docusign-esign/src/index.js
Module not found: Can't resolve 'ApiClient'
Did you mean './ApiClient'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directorie
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

Solution

  • Next.js is a server-based framework that can use server-side rendering, client-side (via React), or static rendering. (I'm new to Next.js, I just researched it a bit to answer your question.)

    To add DocuSign to your Next.js app, read the documentation on calling an external API with Next.js.

    Note that you have two options for calling the DocuSign eSign API:

    1. Use the DocuSign Node.js SDK
    2. Call the API directly

    I recommend that you call the API directly since the marshalling/unmarshalling of JSON objects is so easy in JavaScript.

    Here are several live examples for using the eSign API from JavaScript. (Note that your app should use Authorization Code grant for authentication.)

    The CodePen examples call the 
    DocuSign eSign API directly--
    no SDK is used. 
    This "code" is required by StackOverflow when
    the answer includes a link to CodePen.
    Sigh