0

First, I did read this post (Add permission profile through API) but do not find that it has helped me.

I would like to get a list of users who possess the permission set "DocuiSign Viewer" and set it to "DocuSign Sender".

I am able to connect to and get everything working EXCEPT this function. Below is some sample code.

var permissionSenderId = "123457";
var permissionSenderName = "DocuSign Sender";

data = UrlFetchApp.fetch(url, options);
users = JSON.parse(data).users;
numUsers = users.length;
for(var u = 0, szu = numUsers; u < szu; u++) {
    var user = users[u];
    if(user.isAdmin == "True") continue ;
    if(user.userStatus != "Active") continue ;
    if(user.permissionProfileId != permissionSenderId) {
        user.permissionProfileId = permissionSenderId;
        user.permissionProfileName = permissionSenderName;
        body = JSON.stringify(user);
        url = baseUrl + "/users/"+user.userId;
        options = initializeRequest(url, "PUT", body, email, password, integratorKey);
        data = UrlFetchApp.fetch(url, options);
    }
}

The response I get from the server is:

{
   "errorCode": "INVALID_REQUEST_BODY",
   "message": "The request body is missing or improperly formatted."
}

The response to get the users is below:

{
  "users": [
    {
      "userName": "TestUser",
      "userId": "5b10fac4-5c68-4bee-b2ad-20z68715a8x6",
      "userType": "CompanyUser",
      "isAdmin": "False",
      "userStatus": "Active",
      "uri": "/users/5b10fac4-5c68-4bee-b2ad-20z68715a8x6",
      "email": "do-not-reply@tmx.com",
      "createdDateTime": "2018-05-18T19:04:06.6370000Z",
      "firstName": "Test",
      "lastName": "User",
      "permissionProfileId": "123456",
      "permissionProfileName": "DocuSign Sender",
      "jobTitle": "Test User"
    }
  ],
  "resultSetSize": "1",
  "totalSetSize": "1",
  "startPosition": "0",
  "endPosition": "1"
}

Variations that I have tried:

One:

user.permissionProfileId = permissionSenderId;
user.permissionProfileName = permissionSenderName;
body = JSON.stringify(user);

Two:

body = JSON.stringify({
    "permissionProfileId": permissionSenderId,
    "permissionProfileName": permissionSenderName
});

And other iterations that just feel more like hacking than actual programming. Anyway, I am always getting the same response (noted above). Any thoughts?

(IDs have been fudged to anonymize)

Further reading:

SDK API documentation for updating a user record https://developers.docusign.com/esign-rest-api/reference/Users/Users/update

API Explorer - Under Users > Users, there is no update? :( https://apiexplorer.docusign.com/

A few helper functions I'm using

//***********************************************************************************************
// --- HELPER FUNCTIONS ---
//***********************************************************************************************
function initializeRequest(url, method, body, email, password, integratorKey) {
    var options = {
        "method": method,
        "uri": url,
        "body": body,
        "headers": {},
        "accept": "application/json",
        "contentType": "application/json",
        "content-disposition": "form-data",
        "muteHttpExceptions": true
    };
    addRequestHeaders(options, email, password, integratorKey);
    return options;
}

///////////////////////////////////////////////////////////////////////////////////////////////
function addRequestHeaders(options, email, password, integratorKey) {   
    // JSON formatted authentication header (XML format allowed as well)
    dsAuthHeader = JSON.stringify({
        "Username": email,
        "Password": password, 
        "IntegratorKey": integratorKey
    });
    // DocuSign authorization header
    options.headers["X-DocuSign-Authentication"] = dsAuthHeader;
}
the_gesslar
  • 379
  • 3
  • 13

0 Answers0