Microsoft Advertising API
A Microsoft API that provides programmatic access to Microsoft Advertising to manage large campaigns or to integrate your marketing with other in-house systems.
388 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi, I am trying to make a batch request to insert a product using bing ads content api: [https://learn.microsoft.com/en-us/advertising/shopping-content/products-resource using nodejs. However, I am getting an 400 error code.
I think the issue is how I am defining the Item object this is the code I am using :
var refreshToken = await CustomerManagementService.instance.refreshToken;
var customerId = await CustomerManagementService.instance.getUserId();
var accountId = await CustomerManagementService.instance.GetAccountId();
var authToken = await CustomerManagementService.instance.getAuthToken();
const product = {
availability: "in stock",
brand: brand,
channel: "Local",
condition: "brand new",
contentLanguage: "en",
imageLink: imageLink,
link: link,
offerId: offer_id,
price: {
currency: "USD",
value: 0.00,
},
targetCountry: "GB",
title: title,
};
var productJson = JSON.stringify(product);
var item = {
batchId: 1,
product: productJson,
method: "insert",
merchantId: process.env.STORE_ID,
};
JSON.stringify(item);
var items = [];
items.push(item);
JSON.stringify(items);
var url = 'https://content.api.bingads.microsoft.com/shopping/v9.1/bmc/' + process.env.STORE_ID + '/products/batch';
console.log(`url is ${url}\n`);
const options = {
"method": "POST",
"url": url,
"headers": {
"Content-Type": "application/json",
"AuthenticationToken": `${authToken}`,
"CustomerAccountId": `${accountId}`,
"CustomerId": `${customerId}`,
"DeveloperToken": process.env.DEVELOPER_TOKEN,
},
data: items,
}
await axios(options)
.then(response => {
console.log(response.data);
}).catch(error =>{
console.log(error.message);
});
Can you give me an example of how the Item object should be defined or whether there is another problem with my code. Thank you in advance! Have a wonderful day!