AOTG API: Create Debtor

From AutoCount Resource Center

Create Debtor

Add a new Debtor to account book.

API Method

Http Method: POST
Method: /api/public/v1/Debtor
Content-Type: application/json
Parameters: None

API Request Flow

  1. Submit Create Debtor request
  2. Check the successful request status, if the action is Completed or Failed.
  3. To get the failed reason, use RESULT method to retrieve the message of completed or failed.


Code Snippets

  • Add header of "SOTC_AUTH", and assign value of AccessToken.
  • Description is actually "Desc2" in AutoCount Accounting. It is the 2nd line of the Company Name in AutoCount Accounting.
    Example:
Company Name Alibaba Group Holding Limited
Description (Desc2) 阿里巴巴集团控股有限公司


<?php

$request = new HttpRequest();
$request->setUrl('http://aotg.cloud:8080/api/public/v1/Debtor');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'cache-control' => 'no-cache',
  'SOTC_AUTH' => 'SAMc13a36d2-a139-e911-b8b3-000d3aa04f3d',
  'Content-Type' => 'application/json'
));

$request->setBody('  {
    "CompanyName": "AutoCount On The Go",
    "RegisterNo": "",
    "Description": "AOTG",
    "InvoiceAddress": {
      "Contact": "Mr.Tan",
      "Fax": "",
      "Phone": "02111373",
      "Address1": "1/2, PINE STREET,",
      "Address2": "CENTURY ROAD,",
      "Address3": "SELANGOR",
      "Address4": "50000 MALAYSIA"
    },
    "DeliverAddress": {
      "Contact": "Mr.Tan",
      "Fax": "",
      "Phone": "02111373",
      "Address1": "1/2, PINE STREET,",
      "Address2": "Delivery CENTURY ROAD,",
      "Address3": "SELANGOR",
      "Address4": "50000 MALAYSIA"
    },
    "CreditTerm": "C.O.D.",
    "CreditLimit": 30000,
    "WebURL": "",
    "EmailAddress": "",
    "IsActive": true,
    "CurrencyCode": "MYR",
    "IsTaxRegistered": null
  }');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

var client = new RestClient("http://aotg.cloud:8080/api/public/v1/Debtor");
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("SOTC_AUTH", "SAMc13a36d2-a139-e911-b8b3-000d3aa04f3d");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("undefined", "  {\r\n    \"CompanyName\": \"AutoCount On The Go\",\r\n    \"RegisterNo\": \"\",\r\n    \"Description\": \"AOTG\",\r\n    \"InvoiceAddress\": {\r\n      \"Contact\": \"Mr.Tan\",\r\n      \"Fax\": \"\",\r\n      \"Phone\": \"02111373\",\r\n      \"Address1\": \"1/2, PINE STREET,\",\r\n      \"Address2\": \"CENTURY ROAD,\",\r\n      \"Address3\": \"SELANGOR\",\r\n      \"Address4\": \"50000 MALAYSIA\"\r\n    },\r\n    \"DeliverAddress\": {\r\n      \"Contact\": \"Mr.Tan\",\r\n      \"Fax\": \"\",\r\n      \"Phone\": \"02111373\",\r\n      \"Address1\": \"1/2, PINE STREET,\",\r\n      \"Address2\": \"Delivery CENTURY ROAD,\",\r\n      \"Address3\": \"SELANGOR\",\r\n      \"Address4\": \"50000 MALAYSIA\"\r\n    },\r\n    \"CreditTerm\": \"C.O.D.\",\r\n    \"CreditLimit\": 30000,\r\n    \"WebURL\": \"\",\r\n    \"EmailAddress\": \"\",\r\n    \"IsActive\": true,\r\n    \"CurrencyCode\": \"MYR\",\r\n    \"IsTaxRegistered\": null\r\n  }", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_PORT => "8080",
  CURLOPT_URL => "http://aotg.cloud:8080/api/public/v1/Debtor",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "  {\r\n    \"CompanyName\": \"AutoCount On The Go\",\r\n    \"RegisterNo\": \"\",\r\n    \"Description\": \"AOTG\",\r\n    \"InvoiceAddress\": {\r\n      \"Contact\": \"Mr.Tan\",\r\n      \"Fax\": \"\",\r\n      \"Phone\": \"02111373\",\r\n      \"Address1\": \"1/2, PINE STREET,\",\r\n      \"Address2\": \"CENTURY ROAD,\",\r\n      \"Address3\": \"SELANGOR\",\r\n      \"Address4\": \"50000 MALAYSIA\"\r\n    },\r\n    \"DeliverAddress\": {\r\n      \"Contact\": \"Mr.Tan\",\r\n      \"Fax\": \"\",\r\n      \"Phone\": \"02111373\",\r\n      \"Address1\": \"1/2, PINE STREET,\",\r\n      \"Address2\": \"Delivery CENTURY ROAD,\",\r\n      \"Address3\": \"SELANGOR\",\r\n      \"Address4\": \"50000 MALAYSIA\"\r\n    },\r\n    \"CreditTerm\": \"C.O.D.\",\r\n    \"CreditLimit\": 30000,\r\n    \"WebURL\": \"\",\r\n    \"EmailAddress\": \"\",\r\n    \"IsActive\": true,\r\n    \"CurrencyCode\": \"MYR\",\r\n    \"IsTaxRegistered\": null\r\n  }",
  CURLOPT_HTTPHEADER => array(
    "Content-Type: application/json",
    "SOTC_AUTH: SAMc13a36d2-a139-e911-b8b3-000d3aa04f3d",
    "cache-control: no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

import requests

url = "http://aotg.cloud:8080/api/public/v1/Debtor"

payload = "  {\r\n    \"CompanyName\": \"AutoCount On The Go\",\r\n    \"RegisterNo\": \"\",\r\n    \"Description\": \"AOTG\",\r\n    \"InvoiceAddress\": {\r\n      \"Contact\": \"Mr.Tan\",\r\n      \"Fax\": \"\",\r\n      \"Phone\": \"02111373\",\r\n      \"Address1\": \"1/2, PINE STREET,\",\r\n      \"Address2\": \"CENTURY ROAD,\",\r\n      \"Address3\": \"SELANGOR\",\r\n      \"Address4\": \"50000 MALAYSIA\"\r\n    },\r\n    \"DeliverAddress\": {\r\n      \"Contact\": \"Mr.Tan\",\r\n      \"Fax\": \"\",\r\n      \"Phone\": \"02111373\",\r\n      \"Address1\": \"1/2, PINE STREET,\",\r\n      \"Address2\": \"Delivery CENTURY ROAD,\",\r\n      \"Address3\": \"SELANGOR\",\r\n      \"Address4\": \"50000 MALAYSIA\"\r\n    },\r\n    \"CreditTerm\": \"C.O.D.\",\r\n    \"CreditLimit\": 30000,\r\n    \"WebURL\": \"\",\r\n    \"EmailAddress\": \"\",\r\n    \"IsActive\": true,\r\n    \"CurrencyCode\": \"MYR\",\r\n    \"IsTaxRegistered\": null\r\n  }"
headers = {
    'Content-Type': "application/json",
    'SOTC_AUTH': "SAMc13a36d2-a139-e911-b8b3-000d3aa04f3d",
    'cache-control': "no-cache",
    }

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)


Response

Response Successful HTTP Request

200 OK

Response Successful Body

  • Id and Name can be used to retrieve the status and reason of the failed status.
{
    "Id": "abf79c80-13e9-41ae-993d-2cd6b99b5570",
    "Name": "CreateDebtor",
    "StartTimestamp": "2019-02-27T08:46:06.8497001Z",
    "EndTimestamp": "2019-02-27T08:46:06.8497001Z"
}
AOTG Cloud Server returns successful response when the request has been performed.

But this response does not indicate the status of Create Debtor.
Use RESULT method to acquire the status.


Get Status of the Create Debtor

Code Snippets

<?php

$request = new HttpRequest();
$request->setUrl('http://aotg.cloud:8080/api/public/v1/Result/abf79c80-13e9-41ae-993d-2cd6b99b5570');
$request->setMethod(HTTP_METH_GET);

$request->setHeaders(array(
  'cache-control' => 'no-cache',
  'SOTC_AUTH' => 'SAMc13a36d2-a139-e911-b8b3-000d3aa04f3d'
));

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

var client = new RestClient("http://aotg.cloud:8080/api/public/v1/Result/abf79c80-13e9-41ae-993d-2cd6b99b5570");
var request = new RestRequest(Method.GET);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("SOTC_AUTH", "SAMc13a36d2-a139-e911-b8b3-000d3aa04f3d");
IRestResponse response = client.Execute(request);

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_PORT => "8080",
  CURLOPT_URL => "http://aotg.cloud:8080/api/public/v1/Result/abf79c80-13e9-41ae-993d-2cd6b99b5570",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_POSTFIELDS => "",
  CURLOPT_HTTPHEADER => array(
    "SOTC_AUTH: SAMc13a36d2-a139-e911-b8b3-000d3aa04f3d",
    "cache-control: no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

import requests

url = "http://aotg.cloud:8080/api/public/v1/Result/abf79c80-13e9-41ae-993d-2cd6b99b5570"

payload = ""
headers = {
    'SOTC_AUTH': "SAMc13a36d2-a139-e911-b8b3-000d3aa04f3d",
    'cache-control': "no-cache",
    }

response = requests.request("GET", url, data=payload, headers=headers)

print(response.text)

Response Status

4 possible responses from process status.

InQueue status
  • InQueue status Indicates that the requests to AOTG Server is waiting to be processed.
  • Usually this happen when many requests are called to AOTG Web API in within a second.
    Make sure the request in the loop has pause time,
    or use 'batch' method to process multiple records in single request if applicable.
"RequestId": "abf79c80-13e9-41ae-993d-2cd6b99b5570",
"Status": "InQueue"
Processing status
  • Processing status indicates that the request is not complete.
"RequestId": "abf79c80-13e9-41ae-993d-2cd6b99b5570",
"Status": "Processing"
Completed status
  • Completed status Indicates that the request has been performed and succeeded.
"RequestId": "abf79c80-13e9-41ae-993d-2cd6b99b5570",
"Status": "Completed"
Failed status
  • Failed status indicates that the request has been performed but has error.
"RequestId": "abf79c80-13e9-41ae-993d-2cd6b99b5570",
"Status": "Failed"


Use RESULT method to get the failed reason of Create Debtor request

Code Snippets

<?php

$request = new HttpRequest();
$request->setUrl('http://aotg.cloud:8080/api/public/v1/Result/CreateDebtor/abf79c80-13e9-41ae-993d-2cd6b99b5570/result');
$request->setMethod(HTTP_METH_GET);

$request->setHeaders(array(
  'cache-control' => 'no-cache',
  'SOTC_AUTH' => 'SAMc13a36d2-a139-e911-b8b3-000d3aa04f3d'
));

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

import requests

url = "http://aotg.cloud:8080/api/public/v1/Result/CreateDebtor/abf79c80-13e9-41ae-993d-2cd6b99b5570/result"

payload = ""
headers = {
    'SOTC_AUTH': "SAMc13a36d2-a139-e911-b8b3-000d3aa04f3d",
    'cache-control': "no-cache",
    }

response = requests.request("GET", url, data=payload, headers=headers)

print(response.text)

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_PORT => "8080",
  CURLOPT_URL => "http://aotg.cloud:8080/api/public/v1/Result/CreateDebtor/abf79c80-13e9-41ae-993d-2cd6b99b5570/result",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_POSTFIELDS => "",
  CURLOPT_HTTPHEADER => array(
    "SOTC_AUTH: SAMc13a36d2-a139-e911-b8b3-000d3aa04f3d",
    "cache-control: no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

import requests

url = "http://aotg.cloud:8080/api/public/v1/Result/CreateDebtor/abf79c80-13e9-41ae-993d-2cd6b99b5570/result"

payload = ""
headers = {
    'SOTC_AUTH': "SAMc13a36d2-a139-e911-b8b3-000d3aa04f3d",
    'cache-control': "no-cache",
    }

response = requests.request("GET", url, data=payload, headers=headers)

print(response.text)



See Also AOTG API


Go to menu

Go to top
Resources For AutoCount Software Developers