-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus_update.py
39 lines (31 loc) · 1.03 KB
/
status_update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 4 02:50:26 2023
@author: kpanagias
"""
import requests
import json
def status_update(product_id, status):
store_url = "blablabla.myshopify.com" # Replace with your store URL
access_token = 'blablabla' # Replace with you Access Token
# Validate status
if status not in ['active', 'archive', 'draft']:
print(f"Invalid status: {status}")
return
# Data for the API request
data = {
"product": {
"id": product_id,
"status": status
}
}
# Send a PUT request to update the product
response = requests.put(
f'https://{store_url}/admin/api/2023-04/products/{product_id}.json',
headers={'X-Shopify-Access-Token': access_token, 'Content-Type': 'application/json'},
data=json.dumps(data)
)
if response.status_code == 200:
print(f"Product {product_id} status updated to {status}")
else:
print(f"Failed to update product {product_id} status: {response.content}")