json 无法从Google Apps脚本中了解如何使用JWT auth for Docusign电子签名API进行身份验证

wwodge7n  于 2023-02-10  发布在  Go
关注(0)|答案(1)|浏览(136)

我尝试使用JWT oAuth方法通过DocuSign API进行身份验证以创建模板。我一直收到响应“You need to enable JavaScript to run this app”。我不太擅长连接API,需要一些指导。X-DocuSign-Authenticate方法可以正常工作,但DocuSign在2023年3月之后将不允许REST使用此方法。这是DocuSign演示开发者帐户。
我已经尝试了下面的代码,但不断得到相同的错误.

function createTemplate() {

    var driveFile = DriveApp.getFileById("FILEID");
    var changeorderEncode = Utilities.base64Encode(driveFile.getBlob().getBytes());

    const JWT = "MY_ACCESS_TOKEN";
    const url = 'https://account-d.docusign.com/oauth/token/restapi/v2.1/accounts/<accountid>/templates';

   

   var payload =
   {
     
      "envelopeTemplateDefinition": {
          "name": "TestTemplate5"
      },
        "documents": [
          {
            "documentBase64": changeorderEncode,
            "documentId": "1",
            "fileExtension": "pdf",
            "name": "Change Order Test 5"
          }
        ],
      
      "emailSubject": "1234 Easy St Change Order",
      
   "recipients": {
    
    "signers": [
      {
        "name": "Recipient Name",
        "recipientId": "1",
         "tabs": {
          "signHereTabs": [
            {
              "documentId": "1",
              "pageNumber": "1",
              "tabLabel": "Signature2",
              "xPosition": "407",
              "yPosition": "650"
            },
            {
              "documentId": "1",
              "pageNumber": "1",
              "tabLabel": "Signature",
              "xPosition": "140",
              "yPosition": "650"
            }
          ],
          "dateTabs": [
            {
              "documentId": "1", //notes
              "pageNumber": "1",
              "tabLabel": "date",
              "xPosition": "140",
              "yPosition": "715"
            },
            {
              "documentId": "1",
              "pageNumber": "1",
              "tabLabel": "date",
              "xPosition": "407",
              "yPosition": "715"
            }
          ],
          "textTabs": [
            {
              "documentId": "1",
              "pageNumber": "1",
              "name": "Project Address",
              "value": "1234 Easy St, Roseville, CA 95678",
              "width": 55,
              "xPosition":"76",
              "yPosition":"159"
            }
           ],
          }
         }
        ]
      },
      "status": "created"
    };



   var options =
   {     
     "method" : "post",
     "headers": 
       {
        "grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
        "assertion": JWT,
        "Accept": "application/json",
        "contentType": "application/x-www-form-urlencoded",
        },
     "payload" : JSON.stringify(payload),
     "muteHttpExceptions": true
    };

   var response = UrlFetchApp.fetch(url, options); 
   Logger.log(response.getContentText());
   }
wljmcqd8

wljmcqd81#

您访问的网址不正确。
account-d.docusign.com/oauth/token是用于获取令牌的端点。
您可以从userInfo端点获取baseUrl。所有这些信息都可以在JWT Authentication page上获得
我还认为您的内容类型应该是application/json,因为您发送的是JSON(json.stringify(payload)将其转换为json)
我还将添加一个指向API Reference的链接,它将允许您获取正确的端点和所有端点的有效负载模式

相关问题