API Fetch - not working For Sometime

Hi,
Am trying to POST the data of order from our wix store to Shiprocket (Delivery Partner in India).
But The Code is Working Sometime and Not working for Sometime.

I need to know either Problem with Wix/Velo Or With Shiprocket API.

Please Check below Video.

Above is Successful for Single Product.
And Below Successful for Multiple Product.

And Below is Unsuccessful.

And Below :
The same payload is working when am using POSTMAN

Some one Please tell me What i need to Change with my Code

// Gorgy.in
import { fetch } from ‘wix-fetch’ ;
let TOKEN = “Original Token Will be Here :)” ;

let OrderID = Date.now();
// console.log(OrderID);
export async function wixStores_onOrderPaid(event) {
let today = new Date();

let d = new Date();
let curr_date = d.getDate();
let curr_month = d.getMonth() + 1 ; //Months are zero based

let curr_year = d.getFullYear();
let hour = d.getHours();
let min = d.getMinutes();
let Formatted = (curr_year + “-” + curr_month + “-” + curr_date + " " + hour + “:” + min);
console.log(Formatted);
// console.log(event);

var deliveryDates = new Date();
deliveryDates.setDate(today.getDate() + 5 );

const paidOrderId = event._id;

let items = event.lineItems.map((item) => {
let obj = {
name: item.name,
sku: item.sku,
units: item.quantity,
selling_price: item.price,
discount: item.discount,
tax: item.tax,
hsn: item.index
}
return obj;
})

// console.log("items : ", items)

let DeliveryCompanyName = event.billingInfo.company;
let DeliveryAddress1 = event.billingInfo.address.addressLine.substring( 0 , 49 );
let DeliveryAddress2 = event.billingInfo.address.addressLine.substring( 0 , 49 );
let DeliveryCity = event.billingInfo.address.city;
let DeliveryCounty = event.billingInfo.address.subdivision;
let DeliveryPostCode = event.billingInfo.address.postalCode;
let DeliveryCountry = event.billingInfo.address.country;
let DeliveryPhone = event.billingInfo.phone;
let ReleaseDate = today;
let DeliveryDate = deliveryDates;
let DeliveryTime = event.shippingInfo.estimatedDeliveryTime;

let Weight = event.totals.weight;
let subTotal = event.totals.subtotal;
let discount = event.totals.discount;
let Shipping = event.totals.shipping;
let PaymentMethod = event.billingInfo.paymentMethod;
Weight = Math.ceil(Weight);
// let CustRef = event.billingInfo.firstName + " " + event.billingInfo.lastName;
let firstName = event.billingInfo.firstName;
let lastName = event.billingInfo.lastName;
let email = event.billingInfo.email;
let Remarks = “Notify confirmed delivery details asap!”
let PickItems = event.lineItems;
let NOP = event.totals.quantity;

let payload = {
“order_id” : OrderID,
“order_date” : Formatted,
“pickup_location” : “vijender” ,
“channel_id” : “565097” ,
“comment” : "No Comments " ,
“billing_customer_name” : firstName,
“billing_last_name” : lastName,
“billing_address” : DeliveryAddress1,
“billing_address_2” : DeliveryAddress2,
“billing_city” : DeliveryCity,
“billing_pincode” : DeliveryPostCode,
“billing_state” : DeliveryCounty,
“billing_country” : “INDIA” ,
“billing_email” : email,
“billing_phone” : DeliveryPhone,
“shipping_is_billing” : true ,
“shipping_customer_name” : firstName,
“shipping_last_name” : lastName,
“shipping_address” : DeliveryAddress1,
“shipping_address_2” : DeliveryAddress2,
“shipping_city” : DeliveryCity,
“shipping_pincode” : DeliveryPostCode,
“shipping_country” : “INDIA” ,
“shipping_state” : DeliveryCounty,
“shipping_email” : email,
“shipping_phone” : DeliveryPhone,
“order_items” : items,
“payment_method” : PaymentMethod,
“shipping_charges” : Shipping,
“giftwrap_charges” : 0 ,
“transaction_charges” : 0 ,
“total_discount” : discount,
“sub_total” : subTotal,
“length” : 1 ,
“breadth” : 1 ,
“height” : 1 ,
“weight” : Weight
}

let headers = {
‘Content-type’ : ‘application/json’ ,
‘Authorization’ : ‘Bearer’ + TOKEN
};

// console.log('body string = ', payload);

let options = {
method: ‘POST’ ,
headers: headers,
body: JSON.stringify(payload)
};
console.log(payload);

await fetch( ‘https://apiv2.shiprocket.in/v1/external/orders/create/adhoc’ , options)
.then( async (httpResponse) => {

let status = httpResponse.statusText;
console.log( "status: " , status);
console.log( "response : " , httpResponse.json());

    }) 

    . catch ((error) => { 
        console.log( 'Oops... '  + error +  "ErrorEnd :(" ); 
    }); 

}

Or Please tell me where is the Problem.
Thanks in Advance :slight_smile:

@yisrael-wix
Can you please help me out ?

Hi,
You should open the browser dev tools (F12 key on PC),
and look at the Console tab and the Network tab. Check what error you get when it happens. Then you may be able to understand where the issue is.