The following code is not going to pages 2-4; it’s repeating the same 100 on page 1 throughout.
import requests
from woocommerce import API
import pandas as pd
import json
import csv
from pandas.io.json import json_normalize
wcapi = API(
url="https://site.com",
consumer_key="ck_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
consumer_secret="cs_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
version="wc/v3"
)
orders_p1 = wcapi.get("orders", params={"per_page": 100, "page": 1}).json()
orders_p2 = wcapi.get("orders", params={"per_page": 100, "page": 2}).json()
orders_p3 = wcapi.get("orders", params={"per_page": 100, "page": 3}).json()
orders_p4 = wcapi.get("orders", params={"per_page": 100, "page": 4}).json()
pd.json_normalize(orders_p1)
with open('orders_p1.json', 'w') as f:
json.dump(orders_p1, f)
df.to_excel (r"C:\correct\location\orders_p1.xlsx")
pd.json_normalize(orders_p2)
with open('orders_p2.json', 'w') as f:
json.dump(orders_p2, f)
df.to_excel (r"C:\correct\location\orders_p2.xlsx")
pd.json_normalize(orders_p3)
with open('orders_p3.json', 'w') as f:
json.dump(orders_p3, f)
df.to_excel (r"C:\correct\location\orders_p3.xlsx")
pd.json_normalize(orders_p4)
with open('orders_p4.json', 'w') as f:
json.dump(orders_p4, f)
df.to_excel (r"C:\correct\location\orders_p4.xlsx")