React Native
React Native
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 React Native Downloads
import { Http, JsonObject, StringBuilder } from '@chilkat/react-native'
async function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = new Http();
// 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.authToken = 'YOUR_API_KEY';
http.setRequestHeader('Content-Type', 'application/json');
const sbResponseBody = new StringBuilder();
try {
await http.quickGetSbAsync('https://staging-api.yousign.com/users', sbResponseBody);
} catch {
console.log(http.lastErrorText);
return;
}
const jResp = new JsonObject();
jResp.loadSb(sbResponseBody);
jResp.emitCompact = false;
console.log('Response Body:');
console.log(jResp.emit());
const respStatusCode = http.lastStatus;
console.log(`Response Status Code = ${respStatusCode}`);
if (respStatusCode >= 400) {
console.log('Response Header:');
console.log(http.lastHeader);
console.log('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 name = '';
let strVal = '';
let id = jResp.stringOf('id');
const firstname = jResp.stringOf('firstname');
const lastname = jResp.stringOf('lastname');
const email = jResp.stringOf('email');
const title = jResp.stringOf('title');
const phone = jResp.stringOf('phone');
const status = jResp.stringOf('status');
const organization = jResp.stringOf('organization');
const permission = jResp.stringOf('permission');
const groupId = jResp.stringOf('group.id');
const groupName = jResp.stringOf('group.name');
const createdAt = jResp.stringOf('createdAt');
const updatedAt = jResp.stringOf('updatedAt');
const deletedAt = jResp.stringOf('deletedAt');
const inweboUserRequest = jResp.stringOf('inweboUserRequest');
const samlNameId = jResp.stringOf('samlNameId');
const defaultSignImage = jResp.stringOf('defaultSignImage');
const fullName = jResp.stringOf('fullName');
let i = 0;
let countI = jResp.sizeOfArray('workspaces');
while (i < countI) {
jResp.i = i;
id = jResp.stringOf('workspaces[i].id');
name = jResp.stringOf('workspaces[i].name');
i++;
}
i = 0;
countI = jResp.sizeOfArray('group.permissions');
while (i < countI) {
jResp.i = i;
strVal = jResp.stringOf('group.permissions[i]');
i++;
}
i = 0;
countI = jResp.sizeOfArray('config');
while (i < countI) {
jResp.i = i;
i++;
}
}