Generates a link to a PDF file containing information about one or more specified orders, up to 1000 orders.
The getOrdersLink()
function returns a Promise that resolves to an object containing the URL of a PDF file with the specified orders' information, 1 order per page.
function getOrdersLink(orderIds: Array<string>): Promise<LinkToPdf>;
IDs of the orders for which to generate a PDF file.
/*****************************
* Backend code - orders.jsw *
*****************************/
import wixStoresBackend from "wix-stores-backend";
import wixData from "wix-data";
export function getOrdersLink(orderIds) {
return wixStoresBackend.getOrdersLink(orderIds);
}
// Get IDs of the last 10 paid orders
export function getPaidOrderIds() {
let options = {
suppressAuth: true,
};
return wixData
.query("Stores/Orders")
.eq("paymentStatus", "PAID")
.descending("_dateCreated")
.limit(10)
.find(options)
.then((results) => {
if (results.items.length > 0) {
// Order IDs found
const orderIds = results.items.map((order) => order._id);
return orderIds;
} else {
return "No orders found";
}
})
.catch((error) => {
return error;
});
}
/**************
* Page code *
**************/
import { getOrdersLink, getPaidOrderIds } from "backend/orders";
getPaidOrderIds()
.then((orderIds) => {
getOrdersLink(orderIds)
.then((link) => {
// Orders PDF link retrieved
const orderPdfUrl = link;
})
.catch((error) => {
// Orders PDF link not retrieved
console.error(error);
});
})
.catch((error) => {
// Orders not retrieved from backend
console.error(error);
});
/* Example orderPdfUrl:
*
* {
* link: "https://wixmp-2a4e9...a5977f91b.appspot.com/_api/download/file?downloadToken=E43f...QiOns"
* }
*
*/
This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.