This API allows you to create PO (Purchase Order) line items. It can be used from various sources such as a web browser, native applications in Android, or iOS devices.
URL :
Endpoint:
http://<server-ip-address>/custom_api/capex_track_purchase_order_line_item/create;
Method : Post
| URL Parameters: | Required: |
|---|---|
| format=json (In the future, this parameter might change to become the default format) | Yes |
Form Data Parameters:
| Key | Detail | Value |
|---|---|---|
| business_unit_name | Specify the business unit name. | Almiranta1 / Aurora |
| request_number | The request number associated with the purchase order | AU-2020-4133 |
| PO_number | The purchase order number | 1 |
| general_cost_type_id | ID of the general cost type. | 7 |
| line_item_description | Description of the line item. | |
| asset | The asset related to the line item. | |
| work_order | Work order details. | |
| CER | CER (Cost Estimation Request) information. | |
| quantity | Quantity of items being ordered. | 10 |
| quantity_received | Quantity received for the ordered items. | 895 |
| unit_cost | Unit cost of the items | 9857 |
| PO_line_status | Status of the PO line. | Open |
| deposit | Deposit details. |
Header Parameters :
Authorization :
Bearer <Token> (Include a valid access token to authorize the API request)
Success Response:
Code: 200
Content :
{
"code": 200,
"message": "success",
"data": []
}
Error Responses:
Code: 401 BAD REQUEST
Content :
{
"code": 401,
"message": "fail",
"data": {
"error": "Invalid API Token"
}
}
Code: 400
Content :
{
"code": 400,
"message": "fail",
"data": {
"[field_name]": [
"This field is missing."
]
}
}
Code: 400
{
"code": 400,
"message": "fail",
"data": {
"[PO_number]": "Multiple PO found!"
}
}
Notes : The success response might change in the future if necessary. Ensure you have a valid access token (Bearer Token) in the request header for authorization.
PHP Code :
<?php
// API Endpoint URL
$url = 'http://<server-ip-address>/custom_api/capex_track_purchase_order_line_item/create';
// Form Data Parameters
$data = array(
'business_unit_name' => 'Almiranta1', // Change this value accordingly
'request_number' => 'AU-2020-4133', // Change this value accordingly
'PO_number' => '1', // Change this value accordingly
'general_cost_type_id' => '7', // Change this value accordingly
'line_item_description' => 'Line Item Description', // Change this value accordingly
'asset' => 'Asset', // Change this value accordingly
'work_order' => 'Work Order', // Change this value accordingly
'CER' => 'CER', // Change this value accordingly
'quantity' => '10', // Change this value accordingly
'quantity_received' => '895', // Change this value accordingly
'unit_cost' => '9857', // Change this value accordingly
'PO_line_status' => 'Open', // Change this value accordingly
'deposit' => 'Deposit', // Change this value accordingly
);
// HTTP Header with Authorization Bearer Token
$headers = array(
'Authorization: Bearer <Token>', // Replace <Token> with your actual access token
);
// Initialize cURL session
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Execute cURL session and capture the response
$response = curl_exec($ch);
// Close cURL session
curl_close($ch);
// Process the response
if ($response === false) {
echo 'Error: ' . curl_error($ch);
} else {
// Decode the JSON response
$responseData = json_decode($response, true);
// Check the response code for success/failure
if ($responseData['code'] === 200) {
// Success
echo 'Successfully created PO Line Item!';
} else {
// Failure
echo 'Error: ' . $responseData['message'];
}
}
?>
JavaScript Code (using fetch):
// API Endpoint URL
const url = 'http://<server-ip-address>/custom_api/capex_track_purchase_order_line_item/create';
// Form Data Parameters
const data = new URLSearchParams();
data.append('business_unit_name', 'Almiranta1'); // Change this value accordingly
data.append('request_number', 'AU-2020-4133'); // Change this value accordingly
data.append('PO_number', '1'); // Change this value accordingly
data.append('general_cost_type_id', '7'); // Change this value accordingly
data.append('line_item_description', 'Line Item Description'); // Change this value accordingly
data.append('asset', 'Asset'); // Change this value accordingly
data.append('work_order', 'Work Order'); // Change this value accordingly
data.append('CER', 'CER'); // Change this value accordingly
data.append('quantity', '10'); // Change this value accordingly
data.append('quantity_received', '895'); // Change this value accordingly
data.append('unit_cost', '9857'); // Change this value accordingly
data.append('PO_line_status', 'Open'); // Change this value accordingly
data.append('deposit', 'Deposit'); // Change this value accordingly
// Fetch POST request
fetch(url, {
method: 'POST',
body: data,
headers: {
'Authorization': 'Bearer <Token>', // Replace <Token> with your actual access token
},
})
.then(response => response.json())
.then(responseData => {
// Check the response code for success/failure
if (responseData.code === 200) {
// Success
console.log('Successfully created PO Line Item!');
} else {
// Failure
console.error('Error: ' + responseData.message);
}
})
.catch(error => console.error('Error: ', error));
Note : Replace and in the examples with the actual server IP address and valid access token, respectively. Additionally, make sure to validate the input data on the server-side before processing the request. Also, the actual implementation might vary based on the specific programming environment and libraries used.
Here’s an example of how you can use cURL to make a POST request to the API endpoint:
Explanation :
cURL -X POST :
'http://<server-ip-address>/custom_api/capex_track_purchase_order_line_item/create' \
-H 'Authorization: Bearer <Token>' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'business_unit_name=Almiranta1' \
-d 'request_number=AU-2020-4133' \
-d 'PO_number=1' \
-d 'general_cost_type_id=7' \
-d 'line_item_description=Line Item Description' \
-d 'asset=Asset' \
-d 'work_order=Work Order' \
-d 'CER=CER' \
-d 'quantity=10' \
-d 'quantity_received=895' \
-d 'unit_cost=9857' \
-d 'PO_line_status=Open' \
-d 'deposit=Deposit'
- cURL: The command-line tool to perform HTTP requests.
- -X POST: Specifies that we are making a POST request.
- -H ‘Authorization: Bearer <Token>’: Sets the Authorization header with the Bearer Token. Replace <Token> with your actual access token.
- -H ‘Content-Type: application/x-www-form-urlencoded’: Specifies the content type of the data being sent as URL-encoded form data.
- -d ‘parameter=value’: Adds the form data parameters as key-value pairs in the request body.
- Replace <server-ip-address> and <Token> in the URL and Authorization header, respectively, with the actual server IP address and valid access token.