Sample code for 30+ languages & platforms
Lua

Retrieve User Account Data

See more DocuSign Examples

To make an API call to the DocuSign platform, your application needs both an access token (which you obtained in the previous step), and base URI that is unique to the user on whose behalf your application is making the API call. To get the base URI, call the/oauth/userinfoendpoint, supplying your application’s access token as a header.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local http = chilkat.Http.new()

-- Implements the following CURL command:

-- curl --header "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ" https://account-d.docusign.com/oauth/userinfo

-- Use the following online tool to generate HTTP code from a CURL command
-- Convert a cURL Command to HTTP Source Code

-- Adds the "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ" header.
local jsonToken = chilkat.JsonObject.new()
-- Load a previously obtained OAuth2 access token.
local success = jsonToken:load_file("qa_data/tokens/docusign.json")
if not success then
    print(jsonToken.last_error_text)
    return
end

http.auth_token = jsonToken:string_of("access_token")

local sbResponseBody = chilkat.StringBuilder.new()
success = http:quick_get_sb("https://account-d.docusign.com/oauth/userinfo", sbResponseBody)
if not success then
    print(http.last_error_text)
    return
end

local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false

print("Response Body:")
print(jResp:emit())

local respStatusCode = http.last_status
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
    print("Response Header:")
    print(http.last_response_header)
    print("Failed.")
    return
end

-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)

-- {
--   "sub": "564f7988-xxxx-xxxx-xxxx-781ee556ab7a",
--   "name": "Example J Smith",
--   "given_name": "Example",
--   "family_name": "Smith",
--   "created": "2018-04-13T22:03:03.45",
--   "email": "Example.Smith@exampledomain.com",
--   "accounts": [
--     {
--       "account_id": "18b4799a-xxxx-xxxx-xxxx-b5b4b8a97604",
--       "is_default": true,
--       "account_name": "ExampleAccount",
--       "base_uri": "https://demo.docusign.net"
--     }
--   ]
-- }

-- Sample code for parsing the JSON response...
-- Use the following online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON

local account_id = ""
local is_default = false
local account_name = ""
local base_uri = ""

local sub = jResp:string_of("sub")
local name = jResp:string_of("name")
local given_name = jResp:string_of("given_name")
local family_name = jResp:string_of("family_name")
local created = jResp:string_of("created")
local email = jResp:string_of("email")
local i = 0
local count_i = jResp:size_of_array("accounts")
while i < count_i do
    jResp.i = i
    account_id = jResp:string_of("accounts[i].account_id")
    is_default = jResp:bool_of("accounts[i].is_default")
    account_name = jResp:string_of("accounts[i].account_name")
    base_uri = jResp:string_of("accounts[i].base_uri")
    i = i + 1
end