Swift
Swift
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 Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
// 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.
let jsonToken = CkoJsonObject()!
// Load a previously obtained OAuth2 access token.
success = jsonToken.loadFile(path: "qa_data/tokens/docusign.json")
if success == false {
print("\(jsonToken.lastErrorText!)")
return
}
http.authToken = jsonToken.string(of: "access_token")
// Use an account ID obtained from DocuSign Get User Account Data
let sbResponseBody = CkoStringBuilder()!
success = http.quickGetSb(url: "https://account-d.docusign.com/restapi/v2/accounts/18b4799a-xxxx-xxxx-xxxx-b5b4b8a97604/brands", sbContent: sbResponseBody)
if success == false {
print("\(http.lastErrorText!)")
return
}
let json = CkoJsonObject()!
json.loadSb(sb: sbResponseBody)
json.emitCompact = false
print("Response Body:")
print("\(json.emit()!)")
var respStatusCode: Int = http.lastStatus.intValue
print("Response Status Code = \(respStatusCode)")
if respStatusCode >= 400 {
print("Response Header:")
print("\(http.lastHeader!)")
print("Failed.")
return
}
// 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
var brandCompany: String?
var brandId: String?
var brandName: String?
var errorDetailsErrorCode: String?
var errorDetailsMessage: String?
var isOverridingCompanyName: String?
var isSendingDefault: String?
var isSigningDefault: String?
var logosPrimary: String?
var logosSecondary: String?
var logosEmail: String?
var resourcesEmail: String?
var resourcesSending: String?
var resourcesSigning: String?
var resourcesSigningCaptive: String?
var j: Int
var count_j: Int
var linkType: String?
var urlOrMailTo: String?
var linkText: String?
var showLink: String?
var emailContentType: String?
var content: String?
var emailToLink: String?
var recipientBrandIdDefault: String? = json.string(of: "recipientBrandIdDefault")
var senderBrandIdDefault: String? = json.string(of: "senderBrandIdDefault")
var i: Int = 0
var count_i: Int = json.size(ofArray: "brands").intValue
while i < count_i {
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(ofArray: "brands[i].colors").intValue
while j < count_j {
json.j = j
j = j + 1
}
j = 0
count_j = json.size(ofArray: "brands[i].landingPages").intValue
while j < count_j {
json.j = j
j = j + 1
}
j = 0
count_j = json.size(ofArray: "brands[i].links").intValue
while j < count_j {
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
}
j = 0
count_j = json.size(ofArray: "brands[i].emailContent").intValue
while j < count_j {
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
}
i = i + 1
}
}