PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Http
oleobject loo_JsonToken
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Account_id
integer li_Is_default
string ls_Account_name
string ls_Base_uri
string ls_Sub
string ls_Name
string ls_Given_name
string ls_Family_name
string ls_Created
string ls_Email
integer i
integer li_Count_i
li_Success = 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// 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.
loo_JsonToken = create oleobject
li_rc = loo_JsonToken.ConnectToNewObject("Chilkat.JsonObject")
// Load a previously obtained OAuth2 access token.
li_Success = loo_JsonToken.LoadFile("qa_data/tokens/docusign.json")
if li_Success = 0 then
Write-Debug loo_JsonToken.LastErrorText
destroy loo_Http
destroy loo_JsonToken
return
end if
loo_Http.AuthToken = loo_JsonToken.StringOf("access_token")
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_Http.QuickGetSb("https://account-d.docusign.com/oauth/userinfo",loo_SbResponseBody)
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_JsonToken
destroy loo_SbResponseBody
return
end if
loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Http.LastStatus
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Http.LastResponseHeader
Write-Debug "Failed."
destroy loo_Http
destroy loo_JsonToken
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
// 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
ls_Sub = loo_JResp.StringOf("sub")
ls_Name = loo_JResp.StringOf("name")
ls_Given_name = loo_JResp.StringOf("given_name")
ls_Family_name = loo_JResp.StringOf("family_name")
ls_Created = loo_JResp.StringOf("created")
ls_Email = loo_JResp.StringOf("email")
i = 0
li_Count_i = loo_JResp.SizeOfArray("accounts")
do while i < li_Count_i
loo_JResp.I = i
ls_Account_id = loo_JResp.StringOf("accounts[i].account_id")
li_Is_default = loo_JResp.BoolOf("accounts[i].is_default")
ls_Account_name = loo_JResp.StringOf("accounts[i].account_name")
ls_Base_uri = loo_JResp.StringOf("accounts[i].base_uri")
i = i + 1
loop
destroy loo_Http
destroy loo_JsonToken
destroy loo_SbResponseBody
destroy loo_JResp