get_response = Pass.get(test_pass_id) print "Retrieved Pass..." print get_response print 25*"#" # Now update the pass... # Make a copy of the fields to operate on working_copy = copy.deepcopy(get_response["passFields"]) # modify fields here: working_copy["primary1"]["value"] = "Push Happens!" working_copy["secondary1"]["value"] = "Push Happens Again!" # Call 'update', passing the modifications as input. update_response = Pass.update(test_pass_id, working_copy) print update_response # Retrieve the updated form of that pass just to prove it was updated get_response = Pass.get(test_pass_id) print "Updated Pass..." print get_response print 25*"#" print 25*"#" print "Updated Pass #%s" % test_pass_id print "After update, primary1 says:", get_response["passFields"]["primary1"]["value"] print "After update, secondary1 says:", get_response["passFields"]["secondary1"]["value"] print 25*"#"
# Retrieve the current form of the pass, using the pass ID. current_pass_id = 2039 starting_pass = Pass.get(current_pass_id) # Let's a copy of the fields to operate on pass_fields = copy.deepcopy(starting_pass["passFields"]) print "Starting:" print "Offer:", pass_fields["offer"]["value"] print "Exp_date:", pass_fields["exp_date"]["value"] # Now set the new data. We're going to imagine that our initial offer just expired, and we're setting a '15% off' # offer to extend 'til the end of the year: # NOTE: date values must be passed in iso-8601 format pass_fields["exp_date"]["value"] = "2013-01-01T12:01Z" pass_fields["offer"]["value"] = "15% Off!!!" # Call 'update', passing the modifications as input update_response = Pass.update(current_pass_id, pass_fields) print update_response # At this point, you could retrieve the updated pass, download it, etc. updated_pass = Pass.get(current_pass_id) pass_fields = copy.deepcopy(updated_pass["passFields"]) print "After update:" print "Offer:", pass_fields["offer"]["value"] print "Exp_date:", pass_fields["exp_date"]["value"]
pass_fields = copy.deepcopy(create_response["passFields"]) print 25*"#" print "Start pass update test..." # modify fields here...as an example: if "primary1" in pass_fields: pass_fields["primary1"]["value"] = "Updated Primary!" else: print "No primary1 to update" if "relevantDate" in pass_fields: pass_fields["relevantDate"]["value"] = "2013-01-30T18:30-08:00" else: print "No relevantDate to update" # Call 'update', passing the modifications as input. update_response = Pass.update(new_pass_id, pass_fields) print "Response from pass update..." print update_response get_response = Pass.get(update_response['id']) print "Updated Pass..." print get_response # Note that, after the update, the ID is the same, the serial number is the same, # and any changes you passed in have been incorporated. # If you send the updated pass to a user who has already installed the previous version, # they'll see an "Update" button instead of an "Add" button in the iOS UI. # Btw, you can instantiate a Pass, which gives you some convenience features like pretty-print: updated_pass = Pass() updated_pass.pass_dict = get_response
print 25*"#" print "New Pass at start" print test_pass print 25*"#" # And let's update the "relevantDate" field in that pass # Note that as of this writing, the RelevantDate argument is not format-validated # so you _must_ ensure that the date you pass in confirms to ISO-8601 pass_fields = copy.deepcopy(test_pass["passFields"]) print 25*"#" print "Start pass update..." if "relevantDate" in pass_fields: pass_fields["relevantDate"]["value"] = "2012-01-01T12:00-08:00" # Call 'update', passing the modifications as input update_response = Pass.update(test_pass['id'], pass_fields) print update_response # At this point, you could retrieve the updated pass, download it, etc. updated_pass = Pass.get(test_pass['id']) print "Updated Pass..." print updated_pass print 25*"#" # The update will be returned; note that the ID is the same, the serial number is the same, # and the change to RelevantDate has been incorporated. else: print "No relevantDate to update"