Template Operations¶
The process for creating or updating a template via the python library consists of 3 steps:
Add/remove/set template headers
Add/remove/set template metadata
Add/remove/set template fields
This tutorial explains the relevant classes, methods, and enums for accomplishing the above tasks. In the code samples throughout the tutorial, we assume that the following imports/constants are defined:
import uareach as ua
client = ua.Reach('you@example.com', 'reach-key')
# Initialize the template -- in this example, we create an apple template.
my_template = ua.AppleTemplate()
Metadata¶
When manipulating a template, you’ll use the one of the following methods to update the template metadata:
# Add metadata to the template
my_template.add_metadata(name='A template')
# Remove metadata from the template
my_template.remove_metadata('name')
# Set the template metadata (remove all currently existing metadata, and
# add the specified key/values)
my_template.set_metadata(name='A template', description='Template description')
The table below contains a full listing of available keys for the metadata
methods:
Key |
Description |
Required |
---|---|---|
|
The name of the template. |
Yes |
|
One of |
Yes (set automatically) |
|
One of |
Yes (set automatically) |
|
The type of the project. See template_type for options. |
Yes (alternatively can use |
|
The type of the template. See project_type for options. |
Yes (alternatively can use |
|
Helper key – allows you to set project_type and template_type simultaneously. See type for details. |
No |
|
A boolean representing whether the template is deleted. |
No |
|
A description for the template. |
No |
|
A boolean representing whether the template is disabled. |
No |
|
The template ID. |
No |
|
The ID of the project associated with the template. |
No |
Note
You will either specify both project_type
and template_type
, or you can
use the streamlined type_
key which takes care of setting the two former keys
for you.
Note
When using the remove_metadata
method, you must pass in the Key values as strings
(e.g., 'name'
, 'description'
, etc).
template_type¶
The table below lists possible values for the template_type
key. You can use either
the provided constant or the associated string:
Constant |
Associated String |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
project_type¶
The table below lists possible values for the project_type
key. You can use either
the provided constant or the associated string:
Constant |
Associated String |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type¶
The type_
key provides an alternative to setting both project_type
and
template_type
. You can choose from one of the options listed below:
Type Constant |
---|
|
|
|
|
|
|
|
Headers¶
Template headers specify high-level template options – associated images, template colors, and barcode options are all specified via headers. Available operations on template headers mirror those available for metadata:
# Add headers to the template
apple_coupon.add_headers(
barcode_type='BarcodeFormatPDF417',
logo_image='https://s3.amazonaws.com/passtools_prod/1/images/default-pass-logo.png',
background_color=ua.rgb(0, 147, 201),
logo_color=ua.rgb(24, 86, 148),
foreground_color=ua.rgb(255, 255, 255),
)
# Remove headers from the template
my_template.remove_headers('logo_image')
# Set the template headers (remove all currently existing metadata, and
# add the specified key/values)
my_template.set_headers(
background_color=ua.rgb(0, 147, 201),
logo_color=ua.rgb(24, 86, 148),
foreground_color=ua.rgb(255, 255, 255)
)
See below for a complete listing of available headers:
Key |
Description |
---|---|
|
The background color of the template. |
|
The background image of the template. |
|
The text that displays below the barcode. |
|
The barcode encoding type. Use |
|
The barcode type. See barcode_type for available options. |
|
The actual value represented by the barcode. |
|
Link to image to display in the template footer. |
|
Specify the template foreground color. |
|
Specify the template icon image. |
|
Specify the template logo color (Apple only). |
|
Specify the template logo image. |
|
Specify the text under the template logo. |
|
Specify the barcode strip image. |
|
A boolean – Suppress the strip shine effect on barcodes. |
|
A URL specifying the thumbnail image. |
|
Only used with boarding pass. See transitType (Apple Only) for available options. |
barcode_type¶
See below for a full listing of barcode_type
values. Note that some
barcode types are only available for Google templates.
Constant |
Associated String |
Apple |
|
---|---|---|---|
|
|
Yes |
Yes |
|
|
Yes |
Yes |
|
|
Yes |
Yes |
|
|
Yes |
Yes |
|
|
No |
Yes |
|
|
No |
Yes |
|
|
No |
Yes |
transitType (Apple Only)¶
Transit type is used to specify the type of transportation on
an on Apple Boarding Pass. See below for a full listing of
transitType
values:
Constant |
Associated String |
---|---|
|
|
|
|
|
|
|
|
|
|
Fields¶
The Python Library uses a single field class for both Apple and Google templates.
The Field
class is used to build fields. Let’s look at a simple example:
program_name = ua.Field(
name='Program Name',
label='Program Name',
value='Loyalty Points',
fieldType=ua.AppleFieldType.PRIMARY
)
Note that the only thing that distinguishes this as a field for an Apple Template is
the fieldType
value. Aside from a handful of Google and Apple-specific keys, Apple
and Google field definitions will usually look similar. Here is a roughly analagous field
definition for a Google field:
loyalty_program = ua.Field(
name='Program Name',
label='Program Name',
value='Loyalty Points',
fieldType=ua.GoogleFieldType.TITLE_MODULE
)
Here is a complete listing of valid keys for Field
:
Key |
Value Type |
Apple/Google |
Description |
Additional Notes |
---|---|---|---|---|
|
String |
Both |
The name used to refer to the field. |
|
|
String |
Both |
The label of the field – generally describes the field value. |
|
|
String, Int, or Float |
Both |
The value of the field. |
|
|
String |
Both |
The location of the field on the template. See fieldTypes for options. |
|
|
String |
Both |
The message to display if the field is updated. |
|
|
String |
Both |
The type of value. See formatType for options. |
The python library will attempt to determine this automatically |
|
Boolean |
Both |
Hide the field if no value is specified. |
|
|
Int |
Both |
Specify location within the |
|
|
Boolean |
Both |
Whether the field must be defined when creating passes from the template. |
|
|
String |
Both |
If making a field with a currency value, specify the denomination. See currencyCode for options. |
If you set |
|
String |
Both |
Specify how text is aligned within the field. See textAlignment for options. |
|
|
String |
Apple |
If |
The python library will attempt to determine this automatically |
|
Int |
Specify vertical location within the |
Deprecated, please use |
|
|
Int |
Specify horizontal location within the |
Deprecated, please use |
Note
While the formatType
and numberStyle
keys will be set automatically, you can always
override them. The python library will do its best to guess and should be correct in most
situations, but there may be edge cases where you have to override set these values
explicitly.
formatType¶
The formatType
key specifies the type of argument passed to value
. Generally, the
library can deduce the formatType
without user intervention. However, 'Phone'
and
'Email'
will always have to be specified by the user.
Constant |
Associated String |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fieldTypes¶
The fieldType
key specifies the location of a field on an Apple or Google
template. The available fieldTypes are listed below:
Google fieldTypes:
Constant |
Associated String |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Apple fieldTypes:
Constant |
Associated String |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
numberStyle (Apple Only)¶
The numberStyle
key must be specified for Apple fields with a
formatType
of 'Number'
. Usually, the library can deduce
the appropriate numberStyle
based on the value
argument, but
there still may be situations where it is useful to manually
override the numberStyle
key.
Constant |
Assocaited String |
---|---|
|
|
|
|
|
|
|
|
textAlignment¶
Specify the alignment of the field text:
Constant |
Associated String |
---|---|
|
|
|
|
|
|
|
|
currencyCode¶
Specify the type of currency for Currency
fields:
Constant |
Associated String |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Apple Only Features¶
These methods are specific to the AppleTemplate class.
Beacons¶
To manipulate beacons on a template, use one of the following AppleTemplate methods:
# Add a beacon
my_template.add_beacon(
'55502220-A123-A88A-F321-555A444B333C', # UUID
relevantText="Hey you're in a cool place", # Text displayed on lock screen
major=1, # Major beacon identifier
minor=34 # Minor beacon identifier
)
# Remove a beacon (takes a UUID as argument)
my_template.remove_beacon('55502220-A123-A88A-F321-555A444B333C')
Google Only Features¶
These methods are specific to the GoogleTemplate class.
Offer Module¶
When creating a Google coupon, you can specify an offerModule
. To do so,
use the set_offer
method:
my_template.set_offer(
multiUserOffer=False,
redemptionChannel='both',
provider='The provider',
endTime='2017-01-30T00:00:00.000Z'
)
Valid arguments are listed below:
Key |
Description |
---|---|
|
If true, this offer can be saved by multiple users. Otherwise, the offer is only available for a single user. |
|
Redemption channels applicable to this offer. Can be one of |
|
The provider name. |
|
The offer expiration date. |
Message Module Field¶
To add a message to your template, use the add_message
method:
my_template.add_message(
body='A new message!',
imageUri='https://imgur.com/cool_image.png'
)
Valid arguments are listed below:
Key |
Required |
Description |
---|---|---|
|
Yes |
The message body. |
|
No |
The message title. |
|
No |
The URI to which users are directed upon clicking the message. |
|
No |
Description for the |
|
No |
Specify an image to display with the message. |
|
No |
Description for the image. |
|
No |
Valid ISO8805 date for start time of a message. |
|
No |
Valid ISO8805 date for end time of a message. |