PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkHttp.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkJsonObject.pb"
Procedure ChilkatExample()
success.i = 0
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; 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.
jsonToken.i = CkJsonObject::ckCreate()
If jsonToken.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Load a previously obtained OAuth2 access token.
success = CkJsonObject::ckLoadFile(jsonToken,"qa_data/tokens/docusign.json")
If success = 0
Debug CkJsonObject::ckLastErrorText(jsonToken)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(jsonToken)
ProcedureReturn
EndIf
CkHttp::setCkAuthToken(http, CkJsonObject::ckStringOf(jsonToken,"access_token"))
; Use an account ID obtained from DocuSign Get User Account Data
sbResponseBody.i = CkStringBuilder::ckCreate()
If sbResponseBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkHttp::ckQuickGetSb(http,"https://account-d.docusign.com/restapi/v2/accounts/18b4799a-xxxx-xxxx-xxxx-b5b4b8a97604/brands",sbResponseBody)
If success = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(jsonToken)
CkStringBuilder::ckDispose(sbResponseBody)
ProcedureReturn
EndIf
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoadSb(json,sbResponseBody)
CkJsonObject::setCkEmitCompact(json, 0)
Debug "Response Body:"
Debug CkJsonObject::ckEmit(json)
respStatusCode.i = CkHttp::ckLastStatus(http)
Debug "Response Status Code = " + Str(respStatusCode)
If respStatusCode >= 400
Debug "Response Header:"
Debug CkHttp::ckLastHeader(http)
Debug "Failed."
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(jsonToken)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndIf
; 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
brandCompany.s
brandId.s
brandName.s
errorDetailsErrorCode.s
errorDetailsMessage.s
isOverridingCompanyName.s
isSendingDefault.s
isSigningDefault.s
logosPrimary.s
logosSecondary.s
logosEmail.s
resourcesEmail.s
resourcesSending.s
resourcesSigning.s
resourcesSigningCaptive.s
j.i
count_j.i
linkType.s
urlOrMailTo.s
linkText.s
showLink.s
emailContentType.s
content.s
emailToLink.s
recipientBrandIdDefault.s = CkJsonObject::ckStringOf(json,"recipientBrandIdDefault")
senderBrandIdDefault.s = CkJsonObject::ckStringOf(json,"senderBrandIdDefault")
i.i = 0
count_i.i = CkJsonObject::ckSizeOfArray(json,"brands")
While i < count_i
CkJsonObject::setCkI(json, i)
brandCompany = CkJsonObject::ckStringOf(json,"brands[i].brandCompany")
brandId = CkJsonObject::ckStringOf(json,"brands[i].brandId")
brandName = CkJsonObject::ckStringOf(json,"brands[i].brandName")
errorDetailsErrorCode = CkJsonObject::ckStringOf(json,"brands[i].errorDetails.errorCode")
errorDetailsMessage = CkJsonObject::ckStringOf(json,"brands[i].errorDetails.message")
isOverridingCompanyName = CkJsonObject::ckStringOf(json,"brands[i].isOverridingCompanyName")
isSendingDefault = CkJsonObject::ckStringOf(json,"brands[i].isSendingDefault")
isSigningDefault = CkJsonObject::ckStringOf(json,"brands[i].isSigningDefault")
logosPrimary = CkJsonObject::ckStringOf(json,"brands[i].logos.primary")
logosSecondary = CkJsonObject::ckStringOf(json,"brands[i].logos.secondary")
logosEmail = CkJsonObject::ckStringOf(json,"brands[i].logos.email")
resourcesEmail = CkJsonObject::ckStringOf(json,"brands[i].resources.email")
resourcesSending = CkJsonObject::ckStringOf(json,"brands[i].resources.sending")
resourcesSigning = CkJsonObject::ckStringOf(json,"brands[i].resources.signing")
resourcesSigningCaptive = CkJsonObject::ckStringOf(json,"brands[i].resources.signingCaptive")
j = 0
count_j = CkJsonObject::ckSizeOfArray(json,"brands[i].colors")
While j < count_j
CkJsonObject::setCkJ(json, j)
j = j + 1
Wend
j = 0
count_j = CkJsonObject::ckSizeOfArray(json,"brands[i].landingPages")
While j < count_j
CkJsonObject::setCkJ(json, j)
j = j + 1
Wend
j = 0
count_j = CkJsonObject::ckSizeOfArray(json,"brands[i].links")
While j < count_j
CkJsonObject::setCkJ(json, j)
linkType = CkJsonObject::ckStringOf(json,"brands[i].links[j].linkType")
urlOrMailTo = CkJsonObject::ckStringOf(json,"brands[i].links[j].urlOrMailTo")
linkText = CkJsonObject::ckStringOf(json,"brands[i].links[j].linkText")
showLink = CkJsonObject::ckStringOf(json,"brands[i].links[j].showLink")
j = j + 1
Wend
j = 0
count_j = CkJsonObject::ckSizeOfArray(json,"brands[i].emailContent")
While j < count_j
CkJsonObject::setCkJ(json, j)
emailContentType = CkJsonObject::ckStringOf(json,"brands[i].emailContent[j].emailContentType")
content = CkJsonObject::ckStringOf(json,"brands[i].emailContent[j].content")
emailToLink = CkJsonObject::ckStringOf(json,"brands[i].emailContent[j].emailToLink")
linkText = CkJsonObject::ckStringOf(json,"brands[i].emailContent[j].linkText")
j = j + 1
Wend
i = i + 1
Wend
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(jsonToken)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndProcedure