Create sales order for a customer
| POST | orders/create |
|---|
Leverage this endpoint to efficiently create a sales order on behalf of a customer.
Header
Authorization
Example: Bearer {YOUR_AUTH_KEY}
Content-Type
Example: application/json
Accept
Example: application/json
URL Parameters
| Parameter | Datatype | Description |
|---|---|---|
| customer_id | Integer(required) | The customer's unique identifier. |
Response Parameters
| Parameter | Datatype | Description |
|---|---|---|
| data | object | This object contains the entire resource. |
| id | Integer | The unique identifier for a single order. |
| order_no | String | The unique identifier for a single order. |
| item_total_amount | Double | Total order amount. |
| discount_amount | Double | Total discount availed by the customer. |
| return_total_amount | Double | Total amount of returned products. |
| billable_amount | Double | Total amount payable by the customer. |
| date | DATE | Format (YYYY-MM-DD). |
| products | Collection | The list of products associated with the order. |
| products.id | Integer | The unique product identifier. |
| products.sku | String | The unique product identifier. |
| products.name | String | The product name. |
| products.quantity | Integer | The quantity of the product sold. |
| products.price | Integer | The selling price of the product. |
| customer | Collection | The customer's information associated with the order. |
| customer.id | Integer | The customer's unique identifier. |
| customer.contact_person_name | String | The customer's name. |
| customer.company_name | String | The name of the customer's company. |
| customer.display_name | String | The customer's display name. |
| customer.email | String | The customer's email address. |
| customer.contactperson_number | String | The customer's contact number. |
| customer.company_phone | String | The company's contact number. |
| customer.gst_treatment | String | This indicates whether the customer is GST-registered or not. |
| customer.gstin | String | This is the customer's GST number. |
| customer.customer_code | String | This is the customer's unique identifier code. |
| address | collection | Collection of customer's address. |
| address.addressline1 | String | This is the first line of the customer's address. |
| address.addressline2 | String | This is the second line of the customer's address. |
| address.area | Collection | Collection of area. |
| address.area.id | Integer | The unique identifier of the area. |
| address.area.name | String | The name of the area. |
| address.area.area_code | String | The code of the area. |
| address.area.city | Collection | Collection of city. |
| address.area.city.id | Integer | The unique identifier of the city. |
| address.area.city.name | String | The name of the city. |
| address.area.city.code | String | The code of the city. |
| address.area.city.state | Collection | Collection of state. |
| address.area.city.state.id | Integer | The unique identifier of the state. |
| address.area.city.state.code | String | The code of the state. |
| address.area.city.state.name | String | The name of the state. |
| address.postalcode | Collection | Collection of ZIP code. |
| address.postalcode.id | Integer | The unique identifier of the ZIP code. |
| address.postalcode.code | String | The ZIP code. |
| salesagent | Collection | The salesagent's information associated with the order. |
| salesagent.id | Integer | The salesagent's unique identifier. |
| salesagent.first_name | String | The salesagent's first name. |
| salesagent.last_name | String | The salesagent's last name. |
| salesagent.mobile_number | String | The salesagent's mobile number. |
| salesagent.avatar | String | The full path to the salesagent's avatar image. (Will be null if not available) |
| salesagent.email | String | The salesagent's email address. |
| deliveryagent | Collection | The deliveryagent's information associated with the order. |
| deliveryagent.id | Integer | The deliveryagent's unique identifier. |
| deliveryagent.first_name | String | The deliveryagent's first name. |
| deliveryagent.last_name | String | The deliveryagent's last name. |
| deliveryagent.phone_number | String | The deliveryagent's phone number. |
| laststatus | Collection | The order status information associated with the order. |
| laststatus.name | String | The current status of the order. Possible values include : Placed, Processed, In Review/Invoice Dept, Shipment Created, Delivered, Cancelled, Returned, Invoice Generated, Undelivered & Postponed |
| invoices | Collection | Orders may have multiple invoices. Invoice details associated with the order. |
| invoices.id | Integer | The unique invoice identifier. |
| invoices.invoice_number | String | The unique invoice identifier. |
| invoices.date | DATE | Format YYYY-MM-DD. |
| invoices.due_date | DATE | Format YYYY-MM-DD. Invoice due date. |
| invoices.total_amount | Double | Total sale's amount. |
| invoices.discount_amount | Double | Total discount amount. |
| invoices.returned_amount | Double | Total amount of returned items (If any). |
| invoices.invoice_amount | Double | Total invoice amount. |
| invoices.cgst | Double | Total CGST amount. |
| invoices.sgst | Double | Total SGST amount. |
| invoices.igst | Double | Total IGST amount. |
Sample Request
curl --location --request POST 'https://testwebservices.sourcehub.in/api/orders/create?customer_id=9' \
--header 'Authorization: Bearer ***********'
Sample Success Response
{
"data": {
"id": 41201,
"order_no": "0041127",
"item_total_amount": 600,
"discount_amount": 0,
"return_total_amount": 0,
"billable_amount": 600,
"date": "2024-11-07",
"products": [
{
"id": 4,
"sku": "CP 2425 0046",
"name": "3 Roses Mrp 10 (408pc)",
"quantity": 0,
"price": 0
}
],
"customer": {
"id": 9,
"contact_person_name": "Amit De",
"company_name": "Arobit Business Solutions Pvt Ltd",
"display_name": "Arobit Business Solutions Pvt Ltd",
"email": null,
"contactperson_number": "9163367906",
"company_phone": "9163367906",
"gst_treatment": "Unregistered",
"gstin": null,
"customer_code": "1639328586",
"address": []
},
"salesagent": [],
"deliveryagent": [],
"laststatus": {
"name": "Placed"
},
"invoices": []
},
"message": "Order succesfully placed"
}
Sample 401 Faliure Response
{
"error": {
"code": "AUTHENTICATION_ERROR",
"description": "Invalid credential or token.",
"source": "https://webservices.sourcehub.in/api/orders/874",
"status_code": 401
}
}
Sample 201 Faliure Response
{
"data": {
"unavailable_items_count": 1,
"unavailable_items": [
{
"id": 79532,
"required_qty": 2,
"available_qty": 1,
"product": {
"id": 4,
"name": "3 Roses Mrp 10 (408pc)",
"image": "https://sourcehub.in/public/images/product/1605342130.jpg",
"sku": "CP 2425 0046",
"hsn_code": "0902",
"description": "",
"price_per_unit": 10,
"maximum_retail_price": 4080,
"weight": 3000,
"vol": 0,
"gst_percent": 5,
"measurementtype": {
"id": 5,
"name": "bags"
},
"productcategory": {
"id": 3,
"name": "Tea ,Coffee and Beverages",
"image": "https://sourcehub.in/public/images/productcategory/1617180572.jpg"
},
"productpricing": {
"id": 1058,
"product_id": 4,
"buying_qty": 1,
"price": 200
}
}
}
],
"message": "1 item unavailable"
}
}
Errors
1. The API key/secret provided is invalid. Error Status: 401
The API credentials passed in the API call differ from the ones generated on the Dashboard. Possible reasons are:
- Different keys for test mode and live modes.
- Expired API key.
Solution :
The API keys must be active and entered correctly with no whitespace before or after the keys.
2.UNAVAILABLE. Error Status: 201
Possible reasons are:
- Cart item required quantity is unavailable or low stock.
Solution :
Ordered available quantity or wait for availability.