docusign / docusign-esign-csharp-client

The Official Docusign C# Client Library used to interact with the eSignature REST API. Send, sign, and approve documents using this client.
https://developers.docusign.com/docs/esign-rest-api/sdks/csharp/
MIT License
130 stars 159 forks source link

All my api calls getting "Invalid UserId." response #400

Closed jwilcken closed 1 year ago

jwilcken commented 1 year ago

Here is my Program.cs

using DocuSign.eSign.Api;
using DocuSign.eSign.Client;
using DocuSign.eSign.Model;

var docusignClient = new DocuSignClient();
DocuSign.eSign.Client.Auth.OAuth.OAuthToken accessToken = docusignClient.RequestJWTUserToken(
    "client id",
    "userid",
    "account.docusign.com",
    System.IO.File.ReadAllBytes("privateKey.txt"),
    expiresInHours: 1,
    new List<string> { "signature", "impersonation" }
    );

// I can successfully get my user info and it looks correct.
DocuSign.eSign.Client.Auth.OAuth.UserInfo userInfo = docusignClient.GetUserInfo(accessToken.access_token);

var envelopesApi = new EnvelopesApi(docusignClient);
EnvelopeSummary envelopeSummary = await envelopesApi.CreateEnvelopeAsync(
    userInfo.Accounts[0].AccountId,
    new DocuSign.eSign.Model.EnvelopeDefinition
    {
        // Does not matter what I put in here,
        // the response is always "Invalid UserId."
    }
    );

and here is my csproj file

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="DocuSign.eSign.dll" Version="6.2.0" />
  </ItemGroup>

</Project>

This happens for any endpoint I call. So far I have also tried get envelope by id and list brands.

jwilcken commented 1 year ago

What I was missing was this code right after getting the userInfo

docusignClient = new DocuSignClient(
    new Configuration
    {
        AccessToken = accessToken.access_token,
        BasePath = userInfo.Accounts[1].BaseUri + "/restapi"
     });

Maybe I am bad at reading, but it seems like both the SDK and the docs could be better designed.

Link to my Stack Overflow question https://stackoverflow.com/questions/75678154/why-do-all-my-docusign-calls-return-invalid-userid