Monday, 29 October 2018

browser sent an invalid request to server

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://www.files.fm/u/qvpqhsdc

Please let me know if you need any other information....

I am using ekart api.....

Thanks in Advance....



from browser sent an invalid request to server

No comments:

Post a Comment