06-13-2025 08:02 PM
I'm having some trouble getting the image search API to work. I've tried using Axios and standard node-fetch, but neither of those worked, I've tried using multiple photos between .jpg and .png's, I've generated multiple OAuth tokens, and I've tried different request formats, but I can't seem to get this API to properly return. I know my images are getting encoded correctly and I know my OAuth token is valid because if it isn't, I get a different error. This seems to pertain to the image, although, the image is entirely valid. Can someone let me know what I might be missing? This is using node-fetch in the example below, but I receive the same error output using Axios, so it's definitely consistently reaching the eBay endpoint.
Let me know if you need any more details.
Warnings Output:
"warnings": [
{
"errorId": 12501,
"domain": "API_BROWSE",
"category": "REQUEST",
"message": "The image data is empty, is not Base64 encoded, or is invalid."
}
]
Script:
import fs from 'fs';
import fetch from 'node-fetch';
// CONFIG
const IMAGE_PATH = '[Path to Photo]';
const EBAY_OAUTH_TOKEN = '[OAuth Token]';
const EBAY_API_URL = 'https://api.sandbox.ebay.com/buy/browse/v1/item_summary/search_by_image';
// Read and encode image
const imageBase64 = fs.readFileSync(IMAGE_PATH, { encoding: 'base64' });
console.log('Image size:', fs.statSync(IMAGE_PATH).size);
console.log('Base64 preview:', imageBase64.slice(0, 30));
// Make API Call
fetch(EBAY_API_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${EBAY_OAUTH_TOKEN}`,
'X-EBAY-C-MARKETPLACE-ID': 'EBAY_US',
},
body: JSON.stringify({
image: imageBase64
})
})
.then(response => response.json())
.then(data => {
console.log('RESPONSE:', JSON.stringify(data, null, 2));
})
.catch(error => {
console.error('API call failed:', error);
});