Guest User

Untitled

a guest
Jul 7th, 2024
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. import requests
  2. import json
  3.  
  4. def get_object(object_id, auth_token):
  5. """Retrieve the object from the API using the given object ID."""
  6. url = f"https://connect.squareup.com/v2/catalog/object/{object_id}"
  7. headers = {
  8. 'Square-Version': '2024-06-04',
  9. 'Authorization': f'Bearer {auth_token}',
  10. 'Content-Type': 'application/json'
  11. }
  12. response = requests.get(url, headers=headers)
  13. return response.json()
  14.  
  15. def update_object(auth_token, updated_data):
  16. """Update the object with new data."""
  17. url = "https://connect.squareup.com/v2/catalog/object"
  18. headers = {
  19. 'Square-Version': '2024-06-04',
  20. 'Authorization': f'Bearer {auth_token}',
  21. 'Content-Type': 'application/json'
  22. }
  23. payload = {
  24. 'idempotency_key': 'generated key',
  25. 'object': updated_data
  26. }
  27. response = requests.post(url, headers=headers, json=payload)
  28. return response.json()
  29.  
  30. def main(object_id, auth_token):
  31.  
  32. original_object = get_object(object_id, auth_token)
  33. if 'object' in original_object:
  34.  
  35. obj_data = original_object['object']['item_data']
  36. obj_data['visibility'] = 'PRIVATE'
  37.  
  38.  
  39. obj_data['channels'] = ['CH_blahblah']
  40. for variation in obj_data['variations']:
  41. variation_data = variation['item_variation_data']
  42. variation_data['channels'] = ["CH_blahblah"] # Adding channels array
  43. obj_data['skip_modifier_screen'] = False
  44. obj_data['pickup_fulfillment_preferences_id'] = "fprefs_blah_blah"
  45. obj_data['delivery_fulfillment_preferences_id'] = "fprefs_blah_blah"
  46. obj_data['shipping_fulfillment_preferences_id'] = "fprefs_blah_blah"
  47. obj_data['dine_in_fulfillment_preferences_id'] = "fprefs_blah_blah"
  48.  
  49.  
  50. update_response = update_object(auth_token, original_object['object'])
  51. print('Update Response:', update_response)
  52. else:
  53. print('Failed to retrieve the original object')
  54.  
  55.  
  56. object_id = 'my object id'
  57. auth_token = 'my production token'
  58. main(object_id, auth_token)
Advertisement
Add Comment
Please, Sign In to add comment