Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- def get_object(object_id, auth_token):
- """Retrieve the object from the API using the given object ID."""
- url = f"https://connect.squareup.com/v2/catalog/object/{object_id}"
- headers = {
- 'Square-Version': '2024-06-04',
- 'Authorization': f'Bearer {auth_token}',
- 'Content-Type': 'application/json'
- }
- response = requests.get(url, headers=headers)
- return response.json()
- def update_object(auth_token, updated_data):
- """Update the object with new data."""
- url = "https://connect.squareup.com/v2/catalog/object"
- headers = {
- 'Square-Version': '2024-06-04',
- 'Authorization': f'Bearer {auth_token}',
- 'Content-Type': 'application/json'
- }
- payload = {
- 'idempotency_key': 'generated key',
- 'object': updated_data
- }
- response = requests.post(url, headers=headers, json=payload)
- return response.json()
- def main(object_id, auth_token):
- original_object = get_object(object_id, auth_token)
- if 'object' in original_object:
- obj_data = original_object['object']['item_data']
- obj_data['visibility'] = 'PRIVATE'
- obj_data['channels'] = ['CH_blahblah']
- for variation in obj_data['variations']:
- variation_data = variation['item_variation_data']
- variation_data['channels'] = ["CH_blahblah"] # Adding channels array
- obj_data['skip_modifier_screen'] = False
- obj_data['pickup_fulfillment_preferences_id'] = "fprefs_blah_blah"
- obj_data['delivery_fulfillment_preferences_id'] = "fprefs_blah_blah"
- obj_data['shipping_fulfillment_preferences_id'] = "fprefs_blah_blah"
- obj_data['dine_in_fulfillment_preferences_id'] = "fprefs_blah_blah"
- update_response = update_object(auth_token, original_object['object'])
- print('Update Response:', update_response)
- else:
- print('Failed to retrieve the original object')
- object_id = 'my object id'
- auth_token = 'my production token'
- main(object_id, auth_token)
Advertisement
Add Comment
Please, Sign In to add comment