devmne-me
devmne-me

Reputation: 41

How can I retrieve the UserID from the DocuSign API

Unfortunately, the "docusign/docusign-esign-csharp-client" SDK does not provide a method for requesting the UserID for a given email address.

I was trying to get the UserID by using "CallApi" method from ApiClient. But it didn't work. The response status is always saying "BadRequest".

String postBody = null;
var pathParams = new Dictionary<string, string>();
var queryParams = new Dictionary<string, string>();
var headerParams = new Dictionary<string, string>();
var formParams = new Dictionary<string, string>();
var fileParams = new Dictionary<string, FileParameter>();

var path = $"{ApiClient.Demo_REST_BasePath}/v2.1/accounts/{accountId}/users?email={email}";

headerParams.Add("Authorization", "Bearer " + token.access_token);

var response = (IRestResponse) client.CallApi(path, Method.GET, queryParams, postBody,
                                              headerParams, formParams, fileParams,
                                              pathParams, "application/json");
if (response.IsSuccessful) {
   return response.Content;
}

I'm already using successfully the ApiClient for creating or updating envelopes. But I'm not able to retrieve the UserID.

Maybe someone can help and give me some hints for calling the UserID. Or is there a better way to do this?

Upvotes: 1

Views: 402

Answers (2)

devmne-me
devmne-me

Reputation: 41

I've tested it again and found the issue.

The domain of the ApiClient was already set. Just do:

var path = $"/v2.1/accounts/{accountId}/users?email={email}";

Anyway, requesting the user id can also be done by using the UserApi as @Inbar Gazit wrote.

var api = new UsersApi(client);
var list = api.List(acctId, new UsersApi.ListOptions{email=email});
var id = list.Users.First().UserId;

Upvotes: 0

Inbar Gazit
Inbar Gazit

Reputation: 14015

The "docusign/docusign-esign-csharp-client" SDK actually does provide a method to get this information. The code should look something like this:

Private Sub SurroundingSub()
    Dim usersApi As UsersApi = New UsersApi(apiClient)
    Dim options = New UsersApi.ListOptions()
    options.email = email
    Dim res = usersApi.List(accountId, options)
End Sub

(I tested this code and it worked ok)

Upvotes: 2

Related Questions