title: DocuSign API returns Unauthorized, client error
body: <p>I am trying to obtain a list of all templates a certain user has in its docusign account.
  First of all, I obtain an application access token using the follwing function:</p>
  <pre><code>def get_token():
  
  
      DS_JWT = {
          &quot;ds_client_id&quot;: &quot;79b1adb9-xxxx-xxxx-xxxx-4450dd98a712&quot;,
          &quot;ds_impersonated_user_id&quot;: &quot;3300d1d8-xxxx-xxxx-xxxx-552b87311b0f&quot;,
          &quot;private_key_file&quot;: &quot;private.key&quot;,
          &quot;authorization_server&quot;: &quot;account-d.docusign.com&quot;
      }
  
      private_key = get_private_key(DS_JWT[&quot;private_key_file&quot;]).encode(&quot;ascii&quot;).decode(&quot;utf-8&quot;)
      api_client = ApiClient()
      ds_app = api_client.request_jwt_application_token(
          client_id=DS_JWT[&quot;ds_client_id&quot;],
          oauth_host_name=DS_JWT[&quot;authorization_server&quot;],
          private_key_bytes=private_key,
          expires_in=3600,
          scopes=[&quot;signature&quot;, &quot;impersonation&quot;]
      )
  
      return ds_app.access_token
  </code></pre>
  <p>Once I have the application access token, I am trying to obtain the list of templates:</p>
  <pre><code>def list_templates(token: str):
  
      get_params = {'search_text': 'Test_3'}
      get_headers = {'Authorization': token}
      get_r = requests.get(url=&quot;https://demo.docusign.net/restapi/v2.1/accounts/b24dee2d-xxxx-xxxx-xxxx-d9d81de867ab/templates&quot;, params=get_params, headers=get_headers)
      get_r.raise_for_status()
      data = get_r.json()
      data_templates = data['envelopeTemplates']
      list_templates = []
  
      for inner_data in data_templates:
          for relevant_data_key, relevant_data_value in inner_data.items():
              if relevant_data_key == 'name':
                  list_templates.append(relevant_data_value)
  
      return list_templates
  
  def main():
      load_dotenv(dotenv_path=&quot;.env&quot;, override=True, verbose=True)
  
      token = get_token()
      print(token)
      templates = list_templates(token=token)
      print(templates)
  
  
  if __name__ == '__main__':
      main()
  </code></pre>
  <p>If I use an access token obtained manually and give it as input to the list_templates() function, I obtain the list of templates without any problem.
  But if I use the token obtained using the get_token() function, I obtain the following error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;src/docusign_template_app/obtain_token_4.py&quot;, line 57, in &lt;module&gt;
      main()
    File &quot;src/docusign_template_app/obtain_token_4.py&quot;, line 52, in main
      templates = list_templates(token=token)
    File &quot;src/docusign_template_app/obtain_token_4.py&quot;, line 35, in list_templates
      get_r.raise_for_status()
    File &quot;/home/lluis/.pyenv/versions/docusign-template-app_py38/lib/python3.8/site-packages/requests/models.py&quot;, line 1021, in raise_for_status
      raise HTTPError(http_error_msg, response=self)
  requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://demo.docusign.net/restapi/v2.1/accounts/b24dee2d-xxxx-xxxx-xxxx-d9d81de867ab/templates?search_text=Test_3
  </code></pre>
  <p>Any suggestions are more than welcome! Thanks</p>