I need to call webservice api url & fetch result....
JSON payload provided by API team :
{
"request_id": "R09",
"client_name": "CLIENT",
"services": [
{
"service_code": "REGULAR",
"service_details": [
{
"service_leg": "FORWARD",
"service_data": {
"vendor_name":"Ekart",
"amount_to_collect": 1000,
"dispatch_date": "",
"customer_promise_date": "",
"delivery_type": "SMALL",
"source": {
"address": {
"first_name": "AVThamizhmahan",
"address_line1": "3/1675 ES Garden Vazhudaretty Post Villupuram",
"address_line2": "Tamil Nadu",
"pincode": "400066",
"city": "Villupuram",
"state": "Tamil Nadu",
"primary_contact_number": "88888888"
}
},
"destination": {
"address": {
"first_name": "AVThamizhmahan",
"address_line1": "3/1675 ES Garden Vazhudaretty Post Villupuram",
"address_line2": "Tamil Nadu",
"pincode": "400066",
"city": "Villupuram",
"state": "Tamil Nadu",
"primary_contact_number": "88888888"
}
},
"return_location": {
"address": {
"first_name": "AVThamizhmahan",
"address_line1": "3/1675 ES Garden Vazhudaretty Post Villupuram",
"address_line2": "Tamil Nadu",
"pincode": "400066",
"city": "Villupuram",
"state": "Tamil Nadu",
"primary_contact_number": "88888888"
}
}
},
"shipment": {
"client_reference_id": "ABCD",
"tracking_id": "CLTC0000000001",
"shipment_value": 2000,
"shipment_dimensions": {
"length": {
"value": 1
},
"breadth": {
"value": 1
},
"height": {
"value": 1
},
"weight": {
"value": 1
}
},
"return_label_desc_1": "",
"return_label_desc_2": "",
"shipment_items": [
{
"product_id": "134883075",
"item_content":{},
"category": "Apparel",
"product_title": "Mast&HarbourBlackHandbag: Handbags",
"quantity": 1,
"cost": {
"total_sale_value": 500,
"total_tax_value": 100 ,
“tax_breakup”:{
“cgst”:0.0,
“sgst”:0.0,
“igst”:0.0
}
},
"seller_details": {
"seller_reg_name": "Seller Registered Legal Name",
"vat_id": "",
"cst_id": "",
“tin_id”:””,
“gstin_id”:””
},
“hsn” :””,
“ern”:””,
“discount”:0.0,
"legal_entity": "",
"billable_entity": "",
"cod_remittance_entity": "",
"item_attributes": [
{
"name": "order_id",
"value": "ABCD"
},
{
"name": "invoice_id",
"value": "INV1234"
},
{
"name": "item_dimensions",
"value": "l:b:h:w"
},
{
"name": "brand_name",
"value": "Peter England"
}
],
"handling_attributes": [
{
"name": "isFragile",
"value": "false"
},
{
"name": "isDangerous",
"value": "false"
}
]
}
]
}
}
]
}
]
}
I am calling JSon as array & passing url :
<?php
$url = "https://staging.logistics.com/v2/shipments/create";
$data = array
(
"request_id"=> "R09",
"client_name"=> "DOC",
"services"=> [
array (
"service_code"=> "REGULAR",
"service_details"=> [
array (
"service_leg"=> "FORWARD",
"service_data"=> array (
"vendor_name"=>"Ekart",
"amount_to_collect"=> 1000,
"dispatch_date"=> "",
"customer_promise_date"=> "",
"delivery_type"=> "SMALL",
"source"=> array (
"address"=> array (
"first_name"=> "AVThamizhmahan",
"address_line1"=> "31675 ES Garden Vazhudaretty Post Villupuram",
"address_line2"=> "Tamil Nadu",
"pincode"=> "400066",
"city"=> "Villupuram",
"state"=> "Tamil Nadu",
"primary_contact_number"=> "88888888"
)
),
"destination"=> array (
"address"=> array (
"first_name"=> "AVThamizhmahan",
"address_line1"=> "31675 ES Garden Vazhudaretty Post Villupuram",
"address_line2"=> "Tamil Nadu",
"pincode"=> "400066",
"city"=> "Villupuram",
"state"=> "Tamil Nadu",
"primary_contact_number"=> "88888888"
)
),
"return_location"=> array (
"address"=> array (
"first_name"=> "AVThamizhmahan",
"address_line1"=> "31675 ES Garden Vazhudaretty Post Villupuram",
"address_line2"=> "Tamil Nadu",
"pincode"=> "400066",
"city"=> "Villupuram",
"state"=> "Tamil Nadu",
"primary_contact_number"=> "88888888"
)
)
),
"shipment"=> array (
"client_reference_id"=> "ABCD",
"tracking_id"=> "DOCC0000000001",
"shipment_value"=> 2000,
"shipment_dimensions"=> array (
"length"=> array (
"value"=> 1
),
"breadth"=> array (
"value"=> 1
),
"height"=> array (
"value"=> 1
),
"weight"=> array (
"value"=> 1
)
),
"return_label_desc_1"=> "",
"return_label_desc_2"=> "",
"shipment_items"=> [
array (
"product_id"=> "134883075",
"item_content"=>array (),
"category"=> "Apparel",
"product_title"=> "Mast&HarbourBlackHandbag=> Handbags",
"quantity"=> 1,
"cost"=> array (
"total_sale_value"=> 500,
"total_tax_value"=> 100 ,
"tax_breakup"=>array (
"cgst"=>0.0,
"sgst"=>0.0,
"igst"=>0.0
)
),
"seller_details"=> array (
"seller_reg_name"=> "Seller Registered Legal Name",
"vat_id"=> "",
"cst_id"=> "",
"tin_id"=>"",
"gstin_id"=>""
),
"hsn" =>"",
"ern"=>"",
"discount"=>0.0,
"legal_entity"=> "",
"billable_entity"=> "",
"cod_remittance_entity"=> "",
"item_attributes"=> [
array (
"name"=> "order_id",
"value"=> "ABCD"
),
array (
"name"=> "invoice_id",
"value"=> "INV1234"
),
array (
"name"=> "item_dimensions",
"value"=> "l=>b=>h=>w"
),
array (
"name"=> "brand_name",
"value"=> "Peter England"
)
],
"handling_attributes"=> [
array (
"name"=> "isFragile",
"value"=> "false"
),
array (
"name"=> "isDangerous",
"value"=> "false"
)
]
)
]
)
)
]
)
]
);
echo $data=json_encode($data);
$data_string = json_encode(array(
"Payload" => $data
));
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type : application/json"
));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization : Basic ZGFpbHlvcmRlcnM6ZHVtbf4fsww="
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_setopt($ch, CURLOPT_POST, 1);
curl_close($ch);
echo "$result";
?>
Response :
400 Bad request
Your browser sent an invalid request.
Am i sending in proper format ?
Here is APi Document : https://drive.google.com/open?id=13AstBwus-uErvElg2-FN0knIy1m9lMHa
Please let me know if you need any other information....
I am using ekart api.....
Thanks in Advance....
Update
Below is POSTMAN result :
Update 2 :
Error :
{"response":[{"status":"REQUEST_REJECTED","message":["X_Merchant_Code is null "]}],"request_id":"2aa4cf98-0b59-4e2d-ba10-79c39663d6b6"}
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ALL & ~MYSQLI_REPORT_INDEX);
$url = "https://staging.ekartlogistics.com/v2/shipments/create";
$data1 = array
(
"request_id"=> "835",
"client_name"=> "DOC",
"services"=> [
array (
"service_code"=> "REGULAR",
"service_details"=> [
array (
"service_leg"=> "FORWARD",
"service_data"=> array (
"vendor_name"=>"Ekart",
"amount_to_collect"=> 1000,
"dispatch_date"=> "",
"customer_promise_date"=> "",
"delivery_type"=> "SMALL",
"source"=> array (
"address"=> array (
"first_name"=> "AVThamizhmahan",
"address_line1"=> "31675 ES Garden Vazhudaretty Post Villupuram",
"address_line2"=> "Tamil Nadu",
"pincode"=> "560034",
"city"=> "Villupuram",
"state"=> "Tamil Nadu",
"primary_contact_number"=> "88888888"
)
),
"destination"=> array (
"address"=> array (
"first_name"=> "AVThamizhmahan",
"address_line1"=> "31675 ES Garden Vazhudaretty Post Villupuram",
"address_line2"=> "Tamil Nadu",
"pincode"=> "110037",
"city"=> "Villupuram",
"state"=> "Tamil Nadu",
"primary_contact_number"=> "88888888"
)
),
"return_location"=> array (
"address"=> array (
"first_name"=> "AVThamizhmahan",
"address_line1"=> "31675 ES Garden Vazhudaretty Post Villupuram",
"address_line2"=> "Tamil Nadu",
"pincode"=> "110037",
"city"=> "Villupuram",
"state"=> "Tamil Nadu",
"primary_contact_number"=> "88888888"
)
)
),
"shipment"=> array (
"client_reference_id"=> "ABCD",
"tracking_id"=> "DOCC0000000001",
"shipment_value"=> 2000,
"shipment_dimensions"=> array (
"length"=> array (
"value"=> 1
),
"breadth"=> array (
"value"=> 1
),
"height"=> array (
"value"=> 1
),
"weight"=> array (
"value"=> 1
)
),
"return_label_desc_1"=> "",
"return_label_desc_2"=> "",
"shipment_items"=> [
array (
"product_id"=> "134883075",
"item_content"=>array (),
"category"=> "Apparel",
"product_title"=> "Mast&HarbourBlackHandbag=> Handbags",
"quantity"=> 1,
"cost"=> array (
"total_sale_value"=> 500,
"total_tax_value"=> 100 ,
"tax_breakup"=>array (
"cgst"=>0.0,
"sgst"=>0.0,
"igst"=>0.0
)
),
"seller_details"=> array (
"seller_reg_name"=> "Seller Registered Legal Name",
"vat_id"=> "",
"cst_id"=> "",
"tin_id"=>"",
"gstin_id"=>""
),
"hsn" =>"",
"ern"=>"",
"discount"=>0.0,
"legal_entity"=> "",
"billable_entity"=> "",
"cod_remittance_entity"=> "",
"item_attributes"=> [
array (
"name"=> "order_id",
"value"=> "ABCD"
),
array (
"name"=> "invoice_id",
"value"=> "INV1234"
),
array (
"name"=> "item_dimensions",
"value"=> "l=>b=>h=>w"
),
array (
"name"=> "brand_name",
"value"=> "Peter England"
)
],
"handling_attributes"=> [
array (
"name"=> "isFragile",
"value"=> "false"
),
array (
"name"=> "isDangerous",
"value"=> "false"
)
]
)
]
)
)
]
)
]
);
echo $data=json_encode(array("payload"=>$data1));
echo "<br/><br/>";//die;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Content-Type: application/json", "X_Merchant_Code: DOC"));
curl_setopt($curl, CURLOPT_USERPWD, "dailyorders:dummyKey"); //Your credentials goes here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //IMP if the url has https and you don't want to verify source certificate
$curl_response = curl_exec($curl);
curl_close($curl);
print_r($curl_response);die;
?>