morgan picard
morgan picard

Reputation: 1

Add image to existing listing with Node.js and Etsy API V3

I try to add a picture to an existing listing by Node.js on Etsy API V3. But i get always this message : "Either a valid image file or a listing_image_id must be provided." I've try a lots of things .. This is my last

` addPicturesToProduct = async (findPartner, listingId, files) => {

    const toolController = new ToolController()
    const filePath = toolController.getLocalPathFromUrl(files[0])
    const formData = new FormData();

    formData.append('image', fs.createReadStream(filePath), {
        filename: 'image.png',
        contentType: 'image/png'
    });

    formData.append('name', 'image.png'); 

    try {
        const resp = await fetch(`https://openapi.etsy.com/v3/application/shops/${findPartner.data.shop_id}/listings/${listingId}/images`, {
            method: 'POST',
            headers: {
                'Authorization': `Bearer ${findPartner.token}`,
                'x-api-key': process.env.ETSY_ID_CLIENT,
                'Content-Type': 'multipart/form-data'
            },
            body: formData
        });

        const res = await resp.json()
    
        console.log(res);
    } catch (error) {
        console.error('Error uploading image:', error);
    } 

}`

Someone work with this API ? I have the same problem when i try to upload some files...

Upvotes: 0

Views: 74

Answers (0)

Related Questions