Lua
Lua
Docusign: Return Brand Data Associated with a User
See more DocuSign Examples
Demonstrates a call using an OAuth2 access token in combination with the account ID for which we have authorization.Chilkat Lua Downloads
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 --request GET https://account-d.docusign.com/restapi/v2/accounts/18b4799a-xxxx-xxxx-xxxx-b5b4b8a97604/brands --header "Authorization: Bearer eyJ0eXAi.....UE8Kl_V8KroQ"
-- 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")
-- Use an account ID obtained from DocuSign Get User Account Data
local sbResponseBody = chilkat.StringBuilder.new()
success = http:quick_get_sb("https://account-d.docusign.com/restapi/v2/accounts/18b4799a-xxxx-xxxx-xxxx-b5b4b8a97604/brands", sbResponseBody)
if not success then
print(http.last_error_text)
return
end
local json = chilkat.JsonObject.new()
json:load_sb(sbResponseBody)
json.emit_compact = false
print("Response Body:")
print(json:emit())
local respStatusCode = http.last_status
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
print("Response Header:")
print(http.last_header)
print("Failed.")
return
end
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- {
-- "recipientBrandIdDefault": "sample string 1",
-- "senderBrandIdDefault": "sample string 2",
-- "brands": [
-- {
-- "brandCompany": "sample string 1",
-- "brandId": "sample string 2",
-- "brandName": "sample string 3",
-- "colors": [
-- {}
-- ],
-- "errorDetails": {
-- "errorCode": "sample string 1",
-- "message": "sample string 2"
-- },
-- "isOverridingCompanyName": "sample string 4",
-- "isSendingDefault": "sample string 5",
-- "isSigningDefault": "sample string 6",
-- "landingPages": [
-- {}
-- ],
-- "links": [
-- {
-- "linkType": "sample string 1",
-- "urlOrMailTo": "sample string 2",
-- "linkText": "sample string 3",
-- "showLink": "sample string 4"
-- }
-- ],
-- "emailContent": [
-- {
-- "emailContentType": "sample string 1",
-- "content": "sample string 2",
-- "emailToLink": "sample string 3",
-- "linkText": "sample string 4"
-- }
-- ],
-- "logos": {
-- "primary": "sample string 1",
-- "secondary": "sample string 2",
-- "email": "sample string 3"
-- },
-- "resources": {
-- "email": "sample string 1",
-- "sending": "sample string 2",
-- "signing": "sample string 3",
-- "signingCaptive": "sample string 4"
-- }
-- }
-- ]
-- }
-- 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 brandCompany = ""
local brandId = ""
local brandName = ""
local errorDetailsErrorCode = ""
local errorDetailsMessage = ""
local isOverridingCompanyName = ""
local isSendingDefault = ""
local isSigningDefault = ""
local logosPrimary = ""
local logosSecondary = ""
local logosEmail = ""
local resourcesEmail = ""
local resourcesSending = ""
local resourcesSigning = ""
local resourcesSigningCaptive = ""
local j = 0
local count_j = 0
local linkType = ""
local urlOrMailTo = ""
local linkText = ""
local showLink = ""
local emailContentType = ""
local content = ""
local emailToLink = ""
local recipientBrandIdDefault = json:string_of("recipientBrandIdDefault")
local senderBrandIdDefault = json:string_of("senderBrandIdDefault")
local i = 0
local count_i = json:size_of_array("brands")
while i < count_i do
json.i = i
brandCompany = json:string_of("brands[i].brandCompany")
brandId = json:string_of("brands[i].brandId")
brandName = json:string_of("brands[i].brandName")
errorDetailsErrorCode = json:string_of("brands[i].errorDetails.errorCode")
errorDetailsMessage = json:string_of("brands[i].errorDetails.message")
isOverridingCompanyName = json:string_of("brands[i].isOverridingCompanyName")
isSendingDefault = json:string_of("brands[i].isSendingDefault")
isSigningDefault = json:string_of("brands[i].isSigningDefault")
logosPrimary = json:string_of("brands[i].logos.primary")
logosSecondary = json:string_of("brands[i].logos.secondary")
logosEmail = json:string_of("brands[i].logos.email")
resourcesEmail = json:string_of("brands[i].resources.email")
resourcesSending = json:string_of("brands[i].resources.sending")
resourcesSigning = json:string_of("brands[i].resources.signing")
resourcesSigningCaptive = json:string_of("brands[i].resources.signingCaptive")
j = 0
count_j = json:size_of_array("brands[i].colors")
while j < count_j do
json.j = j
j = j + 1
end
j = 0
count_j = json:size_of_array("brands[i].landingPages")
while j < count_j do
json.j = j
j = j + 1
end
j = 0
count_j = json:size_of_array("brands[i].links")
while j < count_j do
json.j = j
linkType = json:string_of("brands[i].links[j].linkType")
urlOrMailTo = json:string_of("brands[i].links[j].urlOrMailTo")
linkText = json:string_of("brands[i].links[j].linkText")
showLink = json:string_of("brands[i].links[j].showLink")
j = j + 1
end
j = 0
count_j = json:size_of_array("brands[i].emailContent")
while j < count_j do
json.j = j
emailContentType = json:string_of("brands[i].emailContent[j].emailContentType")
content = json:string_of("brands[i].emailContent[j].content")
emailToLink = json:string_of("brands[i].emailContent[j].emailToLink")
linkText = json:string_of("brands[i].emailContent[j].linkText")
j = j + 1
end
i = i + 1
end