简体   繁体   中英

Docusign Node SDK - EnvelopesAPI.createEnvelope() failing with INVALID_REQUEST_PARAMETER

I'm trying to use the Docusign node sdk to create an envelope from a template that already exists in the Docusign developer account.

However I always get a 400 response with this message: {"errorCode":"INVALID_REQUEST_PARAMETER","message":"The request contained at least one invalid parameter. Query parameter 'from_date' must be set to a valid DateTime or 'envelope_ids', 'folder_ids' or 'transaction_ids' must be specified."}

The full error object shows that the request being made is to GET /restapi/v2.1/accounts/{accountId}/envelopes. Which I imagine means it is trying to return the envelope that should have just been created.

I can't see how I can influence this call as it's not called directly.

The process I'm following:

  1. Getting a jwt access token
  2. Initialising the envelopes API
  3. Creating an envelope definition (the templateId variable matches the mid of the template in Docusign)
  4. The create request is sent (the account id is the same one shown in the developer account under Apps and Keys)

The code in question:

      this.dsApiClient.addDefaultHeader(
        'authorization',
        `Bearer ${response.body.access_token}`,
      );
      const envelopesAPI = new EnvelopesApi(this.dsApiClient);
      const envelopeDefinition: EnvelopeDefinition = {
        templateId,
        templateRoles: [
          {
            name: profile.displayName,
            email: profile.defaultEmailAddress,
            clientUserId: profile.personId,
            roleName: 'Demo'
          },
        ],
        status: 'sent',
      };

      const envelope = await envelopesAPI.createEnvelope(
        this.configService.get('docusign.auth.accountId'),
        {
          envelopeDefinition: envelopeDefinition,
        },
      );

However other APIs via the sdk such as

      await templatesApi.listTemplates(this.configService.get('docusign.auth.accountId'))

Return a 200 response and expected data.

You must provide a roleName for any role in your templateRoles in order to send an envelope based on a template. So your code should be like this:

  this.dsApiClient.addDefaultHeader(
    'authorization',
    `Bearer ${response.body.access_token}`,
  );
  const envelopesAPI = new EnvelopesApi(this.dsApiClient);
  const envelopeDefinition: EnvelopeDefinition = {
    templateId,
    templateRoles: [
      {
        name: profile.displayName,
        email: profile.defaultEmailAddress,
        clientUserId: profile.personId,
        roleName: 'yourRoleName'
      },
    ],
    status: 'sent',
  };

  const envelope = await envelopesAPI.createEnvelope(
    this.configService.get('docusign.auth.accountId'),
    {
      envelopeDefinition: envelopeDefinition,
    },
  );

See more information here - https://developers.docusign.com/docs/esign-rest-api/how-to/request-signature-template-remote/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM