Create External project – API

API Authorization

An access token is used to authorize API. For each API call, an access token should be added to the HTTP header of the request like this:

authorization: access_token 1234567890abcdef

Get the access token

The ArcSite will generate an api key and secret for each external application connected to ArcSite.  Go to Advanced Settings / API & Services to request the api key and secret.

Customers should store the key and secret safely.

  1. Compose a string with the “api key” + “secret” + “current time” .
  2. Generate a signature of the string with the md5 method.
  3. Post to server url “/extapi/get_access_token/” to get the access token.

 

URL Path: https://user.arcsiteapp.com/extapi/get_access_token/

Request type: POST

Parameters (send as json data) :

{
  api_key: string; // the api key
  send_time: string; // the datetime string, format is like “'2020-09-06 21:55:30.667827'”
  signature: string; // the signature
}

Returns:

{
  code: int; // result code. success if code == 0
  msg: string; //  api returned messages
  data: {
    access_token: string; // access token
    valid_to: string; // valid to time, string format
  }
}

Sample code (Salesforce Apex):

public static String getAccessToken()
{
  String api_key = 'your_company_api_key';
  String secret_key = 'your_company_secret';
  String signature = '';

  Http httpObj = new Http();
  HttpRequest request = new System.HttpRequest();
  request.setEndpoint('https://user.arcsiteapp.com/extapi/get_access_token/');
  request.setMethod('POST');

  String getTime = string.valueOf(Datetime.Now().getTime()/1000);
  String requestInput = api_key + secret_key + getTime;
  Blob requestBlob = Blob.valueOf(requestInput);
  Blob hash = Crypto.generateDigest('MD5', requestBlob);
  String requestSignature = EncodingUtil.convertToHex(hash);

  Map<String, Object> obj = new Map<String, Object>();
  obj.put('api_key', api_key);
  obj.put('send_time', getTime);
  obj.put('signature', requestSignature);

  request.setBody(JSON.Serialize(obj));
  System.HttpResponse response = httpObj.send(request);

  if (response.getStatusCode() == 200) 
  {
    JSONParser parser = JSON.createParser(response.getBody());
    while (parser.nextToken() != null) 
    {
      if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) && (parser.getText() == 'token')) 
      {
         parser.nextToken();
         return parser.getText()+'';
      }
    }
  }
  return null;
}

Sample code (python):

from datetime import datetime

import requests
import hashlib
import json


api_key = 'your_company_api_key'
secret = 'your_company_secret'


send_time = str(datetime.now())
sign_str = api_key + secret + str(send_time)
h = hashlib.md5()
h.update(sign_str)

payload = {
    'api_key': api_key,
    'send_time': send_time,
    'signature': h.hexdigest()
}

r = requests.post(
    'https://user.arcsiteapp.com/extapi/get_access_token/', data=json.dumps(payload))
result = r.json()
access_token = result['data']['token']
print(access_token)

 

Create an ArcSite Project

Create an ArcSite project with the project name to the owner.

URL Path: https://user.arcsiteapp.com/extapi/projects/create/

Request type: POST
Parameters (send as json data) :

{
  name: string; // Name of project
  owner: string; // Project owner’s email, which will be used as the creator of Project. So it must be an existing user account in ArcSite, otherwise the API call will fail.
  external_info: {
    ext_entity_id: string; // Object id in external system which is connected to the project (ArcSite drawing PDF will be pushed back as attachment via ContentDocumentLink)
    ext_app: string; // Name of external system. For now, only support "SalesForce"
  }
  client_profile: {
    // Customer information of the project
    name: string; // "client name",
    job_number: string; // "job number",
    email: string; // "client email",
    phone: string; // "client phone",
    country: string; // "client detail",
    state: string; // "client detail",
    county: string; // "client detail",
    city: string; // "client detail",
    street: string; // "client detail",
    zip_code: string; // "client detail",
    support_name: string; // "sales representative name",
    support_email: string; // "sales representative email",
    support_phone: string; // "sales representative phone",
    work_site_address: {
      country: string; // "job detail",
      state: string; // "job detail",
      county: string; // "job detail",
      city: string; // "job detail",
      street: string; // "job detail",
      zip_code: string; // "job detail"
    }
  }
}

 

Returns

{
  code: int; // result code. success if code == 0
  msg: string; //  api returned messages
  data: {
    project_id: string; // id of the new project
  }
}

Sample code (python):

import requests
import json

access_token = 'your_company_access_token'

payload = {
    'name': 'test_xxx_1',
    'owner': '444@444.com',
    'external_info': {
        'ext_entity_id': '00Q2v00001fXnmiEAC',
        'ext_app': 'SalesForce',
    },
    'client_profile': {
        'name': 'client name 1',
        'job_number': 'xx',
        'email': '11',
        'phone': 'dd',
        'country': 'ss',
        'stat': 'dd',
        'county': 'xx11',
        'city': '',
        'street': '',
        'zipcode': '',
        'support_name': '',
        'support_email': '',
        'support_phone': '',
        'work_site_address': {
            'country': '22',
            'stat': '22',
            'county': '',
            'city': '',
            'street': '',
            'zipcode': '',
        }
    }
}


r = requests.post('https://user.arcsiteapp.com/extapi/projects/create/',
                  headers={
                      'Authorization': 'access_token {0}'.format(access_token)},
                  data=json.dumps(payload))
print r.json()


More articles in Developer Documentation