Order Upsert API
The API Upserts the Order. The data is sent to the servers for the integration usage. The data is sent to the servers for the integration usage.
API Endpoint
The request is a POST request to the /api/integration/orders endpoint.
Request Structure
POST /api/integration/orders HTTP/1.1{data: [{name: "<name>",email: "<email-id>",phone: "<mobile>",address: "<location>",products: [{product_sku_id: "<product-id>",amount: "<price>",qty: "<quantity>"}],order_id: "<order-id>",total_amount: "<total-amount>",discount: "<discount>",total_qty: "<total-quantity>",refferral_code: "<refferral-code>",user_id: "<user-id>"}]}
Query
| Key | Required | Schema | Description |
|---|---|---|---|
| name | true | String | Name of the person |
| true | String | Email Id | |
| phone | false | String | Mobile Number |
| address | false | String | Location |
| products | true | JSON Value | Array of product details |
| order_id | true | String | Id of the order ordered |
| total_amount | true | Integer | Amount of the Order |
| discount | true | Integer | Discount offered |
| total_qty | false | Integer | Total quantity offered |
| refferral_code | true | String | Refferral Code for getting benefits |
| user_id | true | String | Unique ID offered to the user |
Sample Request
- cURL
- PHP-cUrl
- Node-Axios
- C#-RestSharp
- Python-http.client
- Java-OkHttp
- Go
- Ruby
- C
- PowerShell
curl --location --request POST 'localhost:8000/api/integration/orders' --header 'token: U78FtRBfsMAnecq_q3i8J' --header 'Content-Type: application/json' --data-raw '{"data": [{"name": "Abhay","phone": "7666804987","address": "address 1","products": [{"product_sku_id": "sss1","amount": "25","qty": "1"},{"product_sku_id": "sss2","amount": "25","qty": "1"},{"product_sku_id": "ss3s","amount": "25","qty": "1"},{"product_sku_id": "sss4","amount": "25","qty": "1"}],"order_id": "ID-01","total_amount": "5000","discount": "15","total_qty": "45","refferral_code": "EV78G55H","user_id": "99"}]}'
<?php$curl = curl_init();curl_setopt_array($curl, array(CURLOPT_URL => 'localhost:8000/api/integration/orders',CURLOPT_RETURNTRANSFER => true,CURLOPT_ENCODING => '',CURLOPT_MAXREDIRS => 10,CURLOPT_TIMEOUT => 0,CURLOPT_FOLLOWLOCATION => true,CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,CURLOPT_CUSTOMREQUEST => 'POST',CURLOPT_POSTFIELDS =>'{"data": [{"name": "Abhay","email": "[email protected]","phone": "7666804987","address": "address 1","products": [{"product_sku_id": "sss1","amount": "25","qty": "1"},{"product_sku_id": "sss2","amount": "25","qty": "1"},{"product_sku_id": "ss3s","amount": "25","qty": "1"},{"product_sku_id": "sss4","amount": "25","qty": "1"}],"order_id": "ID-01","total_amount": "5000","discount": "15","total_qty": "45","refferral_code": "EV78G55H","user_id": "99"}]}',CURLOPT_HTTPHEADER => array('token: U78FtRBfsMAnecq_q3i8J','Content-Type: application/json'),));$response = curl_exec($curl);curl_close($curl);echo $response;
var axios = require('axios');var data = JSON.stringify({"data": [{"name": "Abhay","phone": "7666804987","address": "address 1","products": [{"product_sku_id": "sss1","amount": "25","qty": "1"},{"product_sku_id": "sss2","amount": "25","qty": "1"},{"product_sku_id": "ss3s","amount": "25","qty": "1"},{"product_sku_id": "sss4","amount": "25","qty": "1"}],"order_id": "ID-01","total_amount": "5000","discount": "15","total_qty": "45","refferral_code": "EV78G55H","user_id": "99"}]});var config = {method: 'post',url: 'localhost:8000/api/integration/orders',headers: {'token': 'U78FtRBfsMAnecq_q3i8J','Content-Type': 'application/json'},data : data};axios(config).then(function (response) {console.log(JSON.stringify(response.data));}).catch(function (error) {console.log(error);});
var client = new RestClient("localhost:8000/api/integration/orders");client.Timeout = -1;var request = new RestRequest(Method.POST);request.AddHeader("token", "U78FtRBfsMAnecq_q3i8J");request.AddHeader("Content-Type", "application/json");var body = @"{" + "" +@" ""data"": [" + "" +@" {" + "" +@" ""name"": ""Abhay""," + "" +@" ""email"": ""[email protected]""," + "" +@" ""phone"": ""7666804987""," + "" +@" ""address"": ""address 1""," + "" +@" ""products"": [" + "" +@" {" + "" +@" ""product_sku_id"": ""sss1""," + "" +@" ""amount"": ""25""," + "" +@" ""qty"": ""1""" + "" +@" }," + "" +@" {" + "" +@" ""product_sku_id"": ""sss2""," + "" +@" ""amount"": ""25""," + "" +@" ""qty"": ""1""" + "" +@" }," + "" +@" {" + "" +@" ""product_sku_id"": ""ss3s""," + "" +@" ""amount"": ""25""," + "" +@" ""qty"": ""1""" + "" +@" }," + "" +@" {" + "" +@" ""product_sku_id"": ""sss4""," + "" +@" ""amount"": ""25""," + "" +@" ""qty"": ""1""" + "" +@" }" + "" +@" ]," + "" +@" ""order_id"": ""ID-01""," + "" +@" ""total_amount"": ""5000""," + "" +@" ""discount"": ""15""," + "" +@" ""total_qty"": ""45""," + "" +@" ""refferral_code"": ""EV78G55H""," + "" +@" ""user_id"": ""99""" + "" +@" }" + "" +@" ]" + "" +@"}";request.AddParameter("application/json", body, ParameterType.RequestBody);IRestResponse response = client.Execute(request);Console.WriteLine(response.Content);
import http.clientimport jsonconn = http.client.HTTPSConnection("localhost", undefined)payload = json.dumps({"data": [{"name": "Abhay","phone": "7666804987","address": "address 1","products": [{"product_sku_id": "sss1","amount": "25","qty": "1"},{"product_sku_id": "sss2","amount": "25","qty": "1"},{"product_sku_id": "ss3s","amount": "25","qty": "1"},{"product_sku_id": "sss4","amount": "25","qty": "1"}],"order_id": "ID-01","total_amount": "5000","discount": "15","total_qty": "45","refferral_code": "EV78G55H","user_id": "99"}]})headers = {'token': 'U78FtRBfsMAnecq_q3i8J','Content-Type': 'application/json'}conn.request("POST", "/api/integration/orders", payload, headers)res = conn.getresponse()data = res.read()print(data.decode("utf-8"))
OkHttpClient client = new OkHttpClient().newBuilder().build();MediaType mediaType = MediaType.parse("application/json");RequestBody body = RequestBody.create(mediaType, "{"data": [{"name": "Abhay","email": "[email protected]","phone": "7666804987","address": "address 1","products": [{"product_sku_id": "sss1","amount": "25","qty": "1"},{"product_sku_id": "sss2","amount": "25","qty": "1"},{"product_sku_id": "ss3s","amount": "25","qty": "1"},{"product_sku_id": "sss4","amount": "25","qty": "1"}],"order_id": "ID-01","total_amount": "5000","discount": "15","total_qty": "45","refferral_code": "EV78G55H","user_id": "99"}]}");Request request = new Request.Builder().url("localhost:8000/api/integration/orders").method("POST", body).addHeader("token", "U78FtRBfsMAnecq_q3i8J").addHeader("Content-Type", "application/json").build();Response response = client.newCall(request).execute();
package mainimport ("fmt""strings""net/http""io/ioutil")func main() {url := "localhost:8000/api/integration/orders"method := "POST"payload := strings.NewReader(`{`+""+`"data": [`+""+`{`+""+`"name": "Abhay",`+""+`"+`"phone": "7666804987",`+""+`"address": "address 1",`+""+`"products": [`+""+`{`+""+`"product_sku_id": "sss1",`+""+`"amount": "25",`+""+`"qty": "1"`+""+`},`+""+`{`+""+`"product_sku_id": "sss2",`+""+`"amount": "25",`+""+`"qty": "1"`+""+`},`+""+`{`+""+`"product_sku_id": "ss3s",`+""+`"amount": "25",`+""+`"qty": "1"`+""+`},`+""+`{`+""+`"product_sku_id": "sss4",`+""+`"amount": "25",`+""+`"qty": "1"`+""+`}`+""+`],`+""+`"order_id": "ID-01",`+""+`"total_amount": "5000",`+""+`"discount": "15",`+""+`"total_qty": "45",`+""+`"refferral_code": "EV78G55H",`+""+`"user_id": "99"`+""+`}`+""+`]`+""+`}`)client := &http.Client {}req, err := http.NewRequest(method, url, payload)if err != nil {fmt.Println(err)return}req.Header.Add("token", "U78FtRBfsMAnecq_q3i8J")req.Header.Add("Content-Type", "application/json")res, err := client.Do(req)if err != nil {fmt.Println(err)return}defer res.Body.Close()body, err := ioutil.ReadAll(res.Body)if err != nil {fmt.Println(err)return}fmt.Println(string(body))}
require "uri"require "json"require "net/http"url = URI("localhost:8000/api/integration/orders")http = Net::HTTP.new(url.host, url.port);request = Net::HTTP::Post.new(url)request["token"] = "U78FtRBfsMAnecq_q3i8J"request["Content-Type"] = "application/json"request.body = JSON.dump({"data": [{"name": "Abhay","email": "[email protected]","phone": "7666804987","address": "address 1","products": [{"product_sku_id": "sss1","amount": "25","qty": "1"},{"product_sku_id": "sss2","amount": "25","qty": "1"},{"product_sku_id": "ss3s","amount": "25","qty": "1"},{"product_sku_id": "sss4","amount": "25","qty": "1"}],"order_id": "ID-01","total_amount": "5000","discount": "15","total_qty": "45","refferral_code": "EV78G55H","user_id": "99"}]})response = http.request(request)puts response.read_body
CURL *curl;CURLcode res;curl = curl_easy_init();if(curl) {curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");curl_easy_setopt(curl, CURLOPT_URL, "localhost:8000/api/integration/orders");curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");struct curl_slist *headers = NULL;headers = curl_slist_append(headers, "token: U78FtRBfsMAnecq_q3i8J");headers = curl_slist_append(headers, "Content-Type: application/json");curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);const char *data = "{"data": [{"name": "Abhay","phone": "7666804987","address": "address 1","products": [{"product_sku_id": "sss1","amount": "25","qty": "1"},{"product_sku_id": "sss2","amount": "25","qty": "1"},{"product_sku_id": "ss3s","amount": "25","qty": "1"},{"product_sku_id": "sss4","amount": "25","qty": "1"}],"order_id": "ID-01","total_amount": "5000","discount": "15","total_qty": "45","refferral_code": "EV78G55H","user_id": "99"}]}";curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);res = curl_easy_perform(curl);}curl_easy_cleanup(curl);
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"$headers.Add("token", "U78FtRBfsMAnecq_q3i8J")$headers.Add("Content-Type", "application/json")$body = "{`n `"data`": [`n {`n `"name`": `"Abhay`",`n `"email`": `"[email protected]`",`n `"phone`": `"7666804987`",`n `"address`": `"address 1`",`n `"products`": [`n {`n `"product_sku_id`": `"sss1`",`n `"amount`": `"25`",`n `"qty`": `"1`"`n },`n {`n `"product_sku_id`": `"sss2`",`n `"amount`": `"25`",`n `"qty`": `"1`"`n },`n {`n `"product_sku_id`": `"ss3s`",`n `"amount`": `"25`",`n `"qty`": `"1`"`n },`n {`n `"product_sku_id`": `"sss4`",`n `"amount`": `"25`",`n `"qty`": `"1`"`n }`n ],`n `"order_id`": `"ID-01`",`n `"total_amount`": `"5000`",`n `"discount`": `"15`",`n `"total_qty`": `"45`",`n `"refferral_code`": `"EV78G55H`",`n `"user_id`": `"99`"`n }`n ]`n}"$response = Invoke-RestMethod 'localhost:8000/api/integration/orders' -Method 'POST' -Headers $headers -Body $body$response | ConvertTo-Json
Sample Response
POST /api/integration/orders HTTP/1.1{message: "1 new records inserted. 0 existing records updated. Same value or invalid data skipped 0",skipped: 0,inserted: 1,updated: 0}
Error Codes
| Status Code | Description | Response Structure |
|---|---|---|
| 200 | Success | Request Based Response |
| 400 | Bad Request | { "path": "String", "error": "String" } |
| 401 | Unauthorized | { "error": "String" } |
| 500 | Internal server error | { "error": "String" } |