• Resolved reeko6616

    (@reeko6616)


    I have this code that basically fetches images from our wholesale site and is meant to upload them to our retail site as both sites use the same categories however I noticed the API is not adding images to the categories and I do not know why, hoping someone can shed some light, sorry about the mess, quick an dirty

    from woocommerce import API
    import json
    
    wholesale = API(
        url="",
        consumer_key="",
        consumer_secret="",
        wp_api=True,
        version="wc/v3"
    )
    
    retail = API(
        url="",
        consumer_key="",
        consumer_secret="",
        wp_api=True,
        version="wc/v3"
    )
    
    page = 1
    while True:
        categoryData = wholesale.get("products/categories", params={'per_page': 100, 'page': page}).json()
        if len(categoryData) == 0: 
            break
        for item in categoryData:
            try:
                retailcat = retail.get("products/categories/", params={'name': item['name'], 'slug': item['slug']}).json()
                data = {"images": [{"src": "\"" + item['image'].get('src') + "\""}]}
                for item2 in retailcat:
                    retail.put("products/categories/"+str(item2['id']), data).json() 
            except:
                print(item['name'], item['slug'])
        page = page + 1
    • This topic was modified 5 years, 2 months ago by reeko6616.
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Woo API Category Images not uploading’ is closed to new replies.