itemLookUp complete and addItem endpoint

This commit is contained in:
2024-03-21 15:18:06 -05:00
parent ab2b011580
commit 191164f4cc
7 changed files with 162 additions and 4 deletions

View File

@@ -1,9 +1,9 @@
import fetch from "node-fetch";
import fetchEbayToken from "../utils/fetchEbayToken.js"; // Adjust the import path according to your project structure
import fetchEbayReadToken from "../utils/fetchEbayReadToken.js"; // Adjust the import path according to your project structure
export const itemLookup = async (req, res) => {
const productCode = req.query.productCode;
const oauthToken = await fetchEbayToken();
const oauthToken = await fetchEbayReadToken();
console.log(productCode);
try {
const response = await fetch(

View File

@@ -0,0 +1,44 @@
// inventoryController.js
import buildAddItemRequestXML from "../utils/buildAddItemRequestXML.js";
import fetch from "node-fetch";
import fetchEbayUserToken from "../utils/fetchEbayUserToken.js"; // Adjust the import path according to your project structure
export const addItem = async (req, res) => {
const itemDetails = req.body; // Assuming item details are sent in the request body
itemDetails.userToken = await fetchEbayUserToken(); // Fetch and add the user token to itemDetails
const xmlRequest = buildAddItemRequestXML(itemDetails);
try {
const response = await fetch("https://api.ebay.com/ws/api.dll", {
method: "POST",
headers: {
"Content-Type": "text/xml",
"X-EBAY-API-SITEID": "0",
"X-EBAY-API-CALL-NAME": "AddItem",
"X-EBAY-API-COMPATIBILITY-LEVEL": "967", // Ensure this is the current compatibility level
"X-EBAY-API-APP-NAME": process.env.EBAY_CLIENT_ID,
"X-EBAY-API-DEV-NAME": process.env.EBAY_DEV_ID,
"X-EBAY-API-CERT-NAME": process.env.EBAY_CLIENT_SECRET,
},
body: xmlRequest,
});
if (!response.ok) {
throw new Error(`eBay API responded with status ${response.status}`);
}
const responseData = await response.text();
// Parse the XML response and handle it appropriately
// You might need an XML parser here to handle the response
res.json({ success: true, data: responseData }); // Send back a success response
} catch (error) {
console.error("Error adding item to eBay:", error);
res.status(500).json({
success: false,
message: "Failed to add item to eBay",
error: error.message,
});
}
};