HOAB

History of a bug

Facebook and Woocommerce - resync

Rédigé par gorki Aucun commentaire

Problem :

Times to times, Facebook and Woocommerce lost their synchronization. 

In this case, the solution is to reset everything (if you have on Facebook, only your Woocommerce products !!)

Some information there :

But if your catalog is connected to a shop you can not delete your catalog…

And for any reason, the bulk requests was not working for me : accepted, no error, but still all the products ! 

I used : 

https://graph.facebook.com/v15.0/<my shop>/items_batch

{"allow_upsert": "true", "item_type": "PRODUCT_ITEM", "requests": [
{"method": "DELETE", "data": {"id": "1234"}},
{"method": "DELETE", "data": {"id": "2345"}}
{"method": "DELETE", "data": {"id": "3456"}}
]}

Solution :

So I tried to build the request by myself with a short python file : 


import requests

BASE_URL_FACEBOOK = 'https://graph.facebook.com/v16.0'
BASE_URL_FACEBOOK_BOUTIQUE = f'{BASE_URL_FACEBOOK}/<your shop>'
TOKEN = "yourToken"

# You must initialize logging, otherwise you'll not see debug output.
#logging.basicConfig()
#logging.getLogger().setLevel(logging.DEBUG)

url="/products?bulk_pagination=false&summary=true&limit=1000"
print(f'Calling GET : {url}')
hdr = {'User-Agent': r'Facebook-for-WooCommerce/2.6.27 (WooCommerce/6.8.2; WordPress/5.9.5)', 'Accept':'*/*', 'Content-Type': 'application/json', 'Authorization': f"Bearer {TOKEN}"}
response = requests.get(BASE_URL_FACEBOOK_BOUTIQUE + url, headers=hdr)
if response.status_code == 200 or response.status_code == 201:
    print(f'GET OK')
    products_response = response.json()
    delete_products_requests = list()
    print(products_response['summary']['total_count'])
    for product in products_response['data']:
        id = product['id']
        delete_command = {'method': 'DELETE', 'data': {"id":id}}
        delete_products_requests.append(delete_command)
        
    delete_request = dict()
    delete_request['allow_upsert'] = 'true'
    delete_request['item_type'] = 'PRODUCT_ITEM'
    delete_request['requests'] = delete_products_requests

    url="/items_batch"
    print(json.dumps(delete_request))
    response = requests.post(BASE_URL + url, headers=hdr, data=json.dumps(delete_request))
    print(response.status_code)
    print(response.text)
    response.raise_for_status()
    handles = response.json()['handles']
    print(f'handle = {handles}')

And follow the request with : 

https://graph.facebook.com/v16.0/<shop id>/check_batch_request_status?handle=<myHandle from previous request>

Still no error, but nothing deleted (we can follow the batch request in 

Facebook Business Manager > Catalog > Data Source > Application 

At the end, I found the delete request on a single product (simple by slowest) :

import requests


BASE_URL_FACEBOOK = 'https://graph.facebook.com/v16.0'
BASE_URL_FACEBOOK_BOUTIQUE = f'{BASE_URL_FACEBOOK}/<your shop>'
TOKEN = "yourToken"

url="/products?bulk_pagination=false&summary=true&limit=1000"
print(f'Calling GET : {url}')
hdr = {'User-Agent': r'Facebook-for-WooCommerce/2.6.27 (WooCommerce/6.8.2; WordPress/5.9.5)', 'Accept':'*/*', 'Content-Type': 'application/json', 'Authorization': f"Bearer {TOKEN}"}
response = requests.get(BASE_URL_FACEBOOK_BOUTIQUE + url, headers=hdr)
if response.status_code == 200 or response.status_code == 201:
    print(f'GET OK')
    products_response = response.json()
    products = dict()
    delete_products_requests = list()
    print(products_response['summary']['total_count'])
    for product in products_response['data']:
        id = product['id']
        url=f"/{id}"
        response = requests.delete(BASE_URL_FACEBOOK + url, headers=hdr)
        print(f'{response.status_code} : {response.text}')
        if (response.status_code != 200):
            print(f'Can not delete product {id}')

 

 

 

 

Écrire un commentaire

Quelle est le quatrième caractère du mot 4e6dv ?

Fil RSS des commentaires de cet article