AOTG API: Create Debtor: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
Add a new Debtor to account book. |
Add a new Debtor to account book. |
||
{{AOTGApiMethodsSpec|POST|/api/public/v1/Debtor}} |
{{AOTGApiMethodsSpec|POST|/api/public/v1/Debtor}} |
||
==API Request Flow== |
|||
[[File:AOTGApiCompleteOrFailFlow.png|link=]] |
|||
#Submit Create Debtor request |
|||
#Check the successful request status, if the action is completed or failed. |
|||
#To get the failed reason, use RESULT method to retrieve the message of completed or failed. |
|||
<br/> |
<br/> |
||
==Code Snippets== |
==Code Snippets== |
||
Line 60: | Line 66: | ||
echo $response; |
echo $response; |
||
} |
} |
||
</syntaxhighlight> |
|||
|Python= |
|||
<syntaxhighlight lang="Python"> |
|||
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) |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
|PHPHttp= |
|PHPHttp= |
||
Line 120: | Line 143: | ||
200 OK |
200 OK |
||
====Response Successful Body==== |
====Response Successful Body==== |
||
*'''Id''' and '''Name''' can be used to retrieve the status and reason of the failed status. |
|||
Successful created debtor. |
|||
<syntaxhighlight lang="json-object"> |
<syntaxhighlight lang="json-object"> |
||
{ |
{ |
||
Line 129: | Line 152: | ||
} |
} |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{Note|AOTG Cloud Server returns successful response when the request has been performed.<br/> |
|||
But this response does not indicate the status of Create Debtor.<br/> |
|||
Use '''RESULT''' method to acquire the status. |
|||
}} |
|||
<br/> |
|||
==Get Status of the Create Debtor== |
|||
===Code Snippets=== |
|||
{{AOTGApiCodeSnippetTab |
|||
|Python= |
|||
<syntaxhighlight lang="Python"> |
|||
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) |
|||
</syntaxhighlight> |
|||
|PHPHttp= |
|||
<syntaxhighlight lang="PHP"> |
|||
<?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; |
|||
} |
|||
</syntaxhighlight> |
|||
|RestSharp= |
|||
<syntaxhighlight lang="C#"> |
|||
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); |
|||
</syntaxhighlight> |
|||
|PHPcURL= |
|||
<syntaxhighlight lang="PHP"> |
|||
<?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; |
|||
} |
|||
</syntaxhighlight> |
|||
}} |
|||
====Response==== |
|||
200 OK |
|||
=====Completed status===== |
|||
*'''Completed''' status Indicates that the Create debtor request has been performed and succeeded. |
|||
<syntaxhighlight lang="json-object"> |
|||
{ |
|||
"RequestId": "abf79c80-13e9-41ae-993d-2cd6b99b5570", |
|||
"Status": "Completed" |
|||
} |
|||
</syntaxhighlight> |
|||
=====Failed status===== |
|||
*'''Failed''' status Indicates that the Create debtor request has been performed but has error. |
|||
<syntaxhighlight lang="json-object"> |
|||
{ |
|||
"RequestId": "abf79c80-13e9-41ae-993d-2cd6b99b5570", |
|||
"Status": "Failed" |
|||
} |
|||
</syntaxhighlight> |
|||
<br/> |
|||
==Use RESULT method to get the failed reason of Create Debtor request== |
|||
===Code Snippets=== |
|||
{{AOTGApiCodeSnippetTab |
|||
|Python= |
|||
<syntaxhighlight lang="Python"> |
|||
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) |
|||
</syntaxhighlight> |
|||
|PHPHttp= |
|||
<syntaxhighlight lang="PHP"> |
|||
<?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; |
|||
} |
|||
</syntaxhighlight> |
|||
|RestSharp= |
|||
<syntaxhighlight lang="C#"> |
|||
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) |
|||
</syntaxhighlight> |
|||
|PHPcURL= |
|||
<syntaxhighlight lang="PHP"> |
|||
<?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; |
|||
} |
|||
</syntaxhighlight> |
|||
}} |
|||
<br/> |
<br/> |