Sample code for 30+ languages & platforms
Dart

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 Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

void main() {
  // This example assumes the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  final http = CkHttp();

  // 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');

  final sbResponseBody = CkStringBuilder();
  try {
    http.quickGetSb('https://staging-api.yousign.com/users', sbResponseBody);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  final jResp = CkJsonObject();
  jResp.loadSb(sbResponseBody);
  jResp.emitCompact = false;

  print('Response Body:');
  print(jResp.emit());

  final respStatusCode = http.lastStatus;
  print('Response Status Code = $respStatusCode');
  if (respStatusCode >= 400) {
    print('Response Header:');
    print(http.lastHeader);
    print('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

  var name = '';
  var strVal = '';

  var id = jResp.stringOf('id');
  final firstname = jResp.stringOf('firstname');
  final lastname = jResp.stringOf('lastname');
  final email = jResp.stringOf('email');
  final title = jResp.stringOf('title');
  final phone = jResp.stringOf('phone');
  final status = jResp.stringOf('status');
  final organization = jResp.stringOf('organization');
  final permission = jResp.stringOf('permission');
  final groupId = jResp.stringOf('group.id');
  final groupName = jResp.stringOf('group.name');
  final createdAt = jResp.stringOf('createdAt');
  final updatedAt = jResp.stringOf('updatedAt');
  final deletedAt = jResp.stringOf('deletedAt');
  final inweboUserRequest = jResp.stringOf('inweboUserRequest');
  final samlNameId = jResp.stringOf('samlNameId');
  final defaultSignImage = jResp.stringOf('defaultSignImage');
  final fullName = jResp.stringOf('fullName');
  var i = 0;
  var 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++;
  }
}