import axios from "axios"; export default async function handler(req, res) { console.log(process.env.PRODIGI_MERCHANT_ID); console.log(process.env.PRODIGI_API_KEY_TEST); const { body: { image }, method, } = req; const data = { "shippingMethod": "Budget", "recipient": { "address": { "line1": "14 test place", "line2": "test", "postalOrZipCode": "12345", "countryCode": "US", "townOrCity": "somewhere", "stateOrCounty": "somewhereelse" }, "name": "John Testman", "email": "jtestman@prodigi.com" }, "items": [ { "sku": "GLOBAL-FAP-16x24", "copies": 1, "sizing": "fillPrintArea", "assets": [ { "printArea": "default", "url": image } ] } ] }; const headers = { headers: { "X-API-Key": process.env.PRODIGI_API_KEY_TEST, "Content-Type": "application/json" } }; try { const result = await axios.post( "https://api.sandbox.prodigi.com/v4.0/Orders", data, headers ); console.log(result.data); res.status(200).json({ status: "success", metadata: result.data }); } catch (error) { if (error.response) { console.log(error.response.data); console.log(error.response.status); console.log(error.response.headers); } else { console.log(error); } res.status(200).json({ status: "error", message: "Unable to locate metadata." }); } res.status(200).json({ status: "success" }); }