Rust
Rust
Yousign: Making your first API call
See more Yousign Examples
Demonstrates making the simplest of calls to test your API key. This example tests using the sandbox URLs.Chilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
// Implements the following CURL command:
// curl --location --request GET 'https://staging-api.yousign.com/users' \
// --header 'Authorization: Bearer YOUR_API_KEY' \
// --header 'Content-Type: application/json'
// 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 YOUR_API_KEY" header.
http.set_auth_token("YOUR_API_KEY");
http.set_request_header("Content-Type", "application/json");
let sb_response_body = chilkat::StringBuilder::new();
if http.quick_get_sb("https://staging-api.yousign.com/users", &sb_response_body).is_err() {
println!("{}", http.last_error_text());
return;
}
let j_resp = chilkat::JsonObject::new();
let _ = j_resp.load_sb(&sb_response_body);
j_resp.set_emit_compact(false);
println!("Response Body:");
println!("{}", j_resp.emit().unwrap_or_default());
let resp_status_code = http.last_status();
println!("Response Status Code = {}", resp_status_code);
if resp_status_code >= 400 {
println!("Response Header:");
println!("{}", http.last_header());
println!("Failed.");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "id": "/users/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "firstname": "John",
// "lastname": "Doe",
// "email": "john.doe@yousign.fr",
// "title": "Developer",
// "phone": "+33612345678",
// "status": "activated",
// "organization": "/organizations/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "workspaces": [
// {
// "id": "/workspaces/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "name": "Acme"
// }
// ],
// "permission": "ROLE_ADMIN",
// "group": {
// "id": "/user_groups/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
// "name": "Administrateur",
// "permissions": [
// "procedure_write",
// "procedure_template_write",
// "procedure_create_from_template",
// "contact",
// "sign",
// "organization",
// "user",
// "api_key",
// "procedure_custom_field",
// "signature_ui",
// "certificate",
// "archive"
// ]
// },
// "createdAt": "2018-12-01T09:42:25+01:00",
// "updatedAt": "2018-12-01T09:42:25+01:00",
// "deleted": false,
// "deletedAt": null,
// "config": [
// ],
// "inweboUserRequest": null,
// "samlNameId": null,
// "defaultSignImage": null,
// "notifications": {
// "procedure": true
// },
// "fastSign": false,
// "fullName": "John Doe"
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
let mut id = j_resp.string_of("id").unwrap_or_default();
let firstname = j_resp.string_of("firstname").unwrap_or_default();
let lastname = j_resp.string_of("lastname").unwrap_or_default();
let email = j_resp.string_of("email").unwrap_or_default();
let title = j_resp.string_of("title").unwrap_or_default();
let phone = j_resp.string_of("phone").unwrap_or_default();
let status = j_resp.string_of("status").unwrap_or_default();
let organization = j_resp.string_of("organization").unwrap_or_default();
let permission = j_resp.string_of("permission").unwrap_or_default();
let group_id = j_resp.string_of("group.id").unwrap_or_default();
let group_name = j_resp.string_of("group.name").unwrap_or_default();
let created_at = j_resp.string_of("createdAt").unwrap_or_default();
let updated_at = j_resp.string_of("updatedAt").unwrap_or_default();
let deleted = j_resp.bool_of("deleted");
let deleted_at = j_resp.string_of("deletedAt").unwrap_or_default();
let inwebo_user_request = j_resp.string_of("inweboUserRequest").unwrap_or_default();
let saml_name_id = j_resp.string_of("samlNameId").unwrap_or_default();
let default_sign_image = j_resp.string_of("defaultSignImage").unwrap_or_default();
let notifications_procedure = j_resp.bool_of("notifications.procedure");
let fast_sign = j_resp.bool_of("fastSign");
let full_name = j_resp.string_of("fullName").unwrap_or_default();
let mut i = 0;
let mut count_i = j_resp.size_of_array("workspaces");
while i < count_i {
j_resp.set_i(i);
id = j_resp.string_of("workspaces[i].id").unwrap_or_default();
let _ = j_resp.string_of("workspaces[i].name").unwrap_or_default();
i = i + 1;
}
i = 0;
count_i = j_resp.size_of_array("group.permissions");
while i < count_i {
j_resp.set_i(i);
let _ = j_resp.string_of("group.permissions[i]").unwrap_or_default();
i = i + 1;
}
i = 0;
count_i = j_resp.size_of_array("config");
while i < count_i {
j_resp.set_i(i);
i = i + 1;
}