Zig
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// 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.
const json_token = try chilkat.JsonObject.init();
defer json_token.deinit();
// Load a previously obtained OAuth2 access token.
json_token.loadFile("qa_data/tokens/docusign.json") catch {
std.debug.print("{s}\n", .{try json_token.getLastErrorText(alloc)});
return;
};
http.setAuthToken(try json_token.stringOf(alloc, "access_token"));
// Use an account ID obtained from DocuSign Get User Account Data
const sb_response_body = try chilkat.StringBuilder.init();
defer sb_response_body.deinit();
http.quickGetSb("https://account-d.docusign.com/restapi/v2/accounts/18b4799a-xxxx-xxxx-xxxx-b5b4b8a97604/brands", sb_response_body) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.loadSb(sb_response_body) catch {};
json.setEmitCompact(false);
std.debug.print("Response Body:\n", .{});
std.debug.print("{s}\n", .{try json.emit(alloc)});
const resp_status_code = http.getLastStatus();
std.debug.print("Response Status Code = {d}\n", .{resp_status_code});
if (resp_status_code >= 400) {
std.debug.print("Response Header:\n", .{});
std.debug.print("{s}\n", .{try http.getLastHeader(alloc)});
std.debug.print("Failed.\n", .{});
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 brand_company: [:0]const u8 = "";
var brand_id: [:0]const u8 = "";
var brand_name: [:0]const u8 = "";
var error_details_error_code: [:0]const u8 = "";
var error_details_message: [:0]const u8 = "";
var is_overriding_company_name: [:0]const u8 = "";
var is_sending_default: [:0]const u8 = "";
var is_signing_default: [:0]const u8 = "";
var logos_primary: [:0]const u8 = "";
var logos_secondary: [:0]const u8 = "";
var logos_email: [:0]const u8 = "";
var resources_email: [:0]const u8 = "";
var resources_sending: [:0]const u8 = "";
var resources_signing: [:0]const u8 = "";
var resources_signing_captive: [:0]const u8 = "";
var j: i32 = 0;
var count_j: i32 = 0;
var link_type: [:0]const u8 = "";
var url_or_mail_to: [:0]const u8 = "";
var link_text: [:0]const u8 = "";
var show_link: [:0]const u8 = "";
var email_content_type: [:0]const u8 = "";
var content: [:0]const u8 = "";
var email_to_link: [:0]const u8 = "";
_ = try json.stringOf(alloc, "recipientBrandIdDefault");
_ = try json.stringOf(alloc, "senderBrandIdDefault");
var i: i32 = 0;
const count_i = json.sizeOfArray("brands");
while (i < count_i) {
json.setI(i);
brand_company = try json.stringOf(alloc, "brands[i].brandCompany");
brand_id = try json.stringOf(alloc, "brands[i].brandId");
brand_name = try json.stringOf(alloc, "brands[i].brandName");
error_details_error_code = try json.stringOf(alloc, "brands[i].errorDetails.errorCode");
error_details_message = try json.stringOf(alloc, "brands[i].errorDetails.message");
is_overriding_company_name = try json.stringOf(alloc, "brands[i].isOverridingCompanyName");
is_sending_default = try json.stringOf(alloc, "brands[i].isSendingDefault");
is_signing_default = try json.stringOf(alloc, "brands[i].isSigningDefault");
logos_primary = try json.stringOf(alloc, "brands[i].logos.primary");
logos_secondary = try json.stringOf(alloc, "brands[i].logos.secondary");
logos_email = try json.stringOf(alloc, "brands[i].logos.email");
resources_email = try json.stringOf(alloc, "brands[i].resources.email");
resources_sending = try json.stringOf(alloc, "brands[i].resources.sending");
resources_signing = try json.stringOf(alloc, "brands[i].resources.signing");
resources_signing_captive = try json.stringOf(alloc, "brands[i].resources.signingCaptive");
j = 0;
count_j = json.sizeOfArray("brands[i].colors");
while (j < count_j) {
json.setJ(j);
j = j + 1;
}
j = 0;
count_j = json.sizeOfArray("brands[i].landingPages");
while (j < count_j) {
json.setJ(j);
j = j + 1;
}
j = 0;
count_j = json.sizeOfArray("brands[i].links");
while (j < count_j) {
json.setJ(j);
link_type = try json.stringOf(alloc, "brands[i].links[j].linkType");
url_or_mail_to = try json.stringOf(alloc, "brands[i].links[j].urlOrMailTo");
link_text = try json.stringOf(alloc, "brands[i].links[j].linkText");
show_link = try json.stringOf(alloc, "brands[i].links[j].showLink");
j = j + 1;
}
j = 0;
count_j = json.sizeOfArray("brands[i].emailContent");
while (j < count_j) {
json.setJ(j);
email_content_type = try json.stringOf(alloc, "brands[i].emailContent[j].emailContentType");
content = try json.stringOf(alloc, "brands[i].emailContent[j].content");
email_to_link = try json.stringOf(alloc, "brands[i].emailContent[j].emailToLink");
link_text = try json.stringOf(alloc, "brands[i].emailContent[j].linkText");
j = j + 1;
}
i = i + 1;
}
}