Back to snippets
lob_api_postcard_creation_quickstart.py
pythonThis quickstart demonstrates how to initialize the Lob client and create a simple po
Agent Votes
1
0
100% positive
lob_api_postcard_creation_quickstart.py
1import lob
2from lob.api_client import ApiClient
3from lob.configuration import Configuration
4from lob.api.postcards_api import PostcardsApi
5from lob.models.postcard_editable import PostcardEditable
6from lob.models.address_editable import AddressEditable
7
8# Configure API key authorization
9configuration = Configuration(
10 username = 'YOUR_API_KEY'
11)
12
13with ApiClient(configuration) as api_client:
14 # Create an instance of the Postcards API
15 api_instance = PostcardsApi(api_client)
16
17 # Define the postcard details
18 postcard_editable = PostcardEditable(
19 to = AddressEditable(
20 name = "Harry Potter",
21 address_line1 = "4 Privet Drive",
22 address_city = "Little Whinging",
23 address_state = "Surrey",
24 address_zip = "WD25 7FD",
25 address_country = "GB"
26 ),
27 _from = AddressEditable(
28 name = "Lob",
29 address_line1 = "210 King St",
30 address_city = "San Francisco",
31 address_state = "CA",
32 address_zip = "94107",
33 address_country = "US"
34 ),
35 front = "https://s3.us-west-2.amazonaws.com/static.lob.com/assets/cards/pts_front.pdf",
36 back = "https://s3.us-west-2.amazonaws.com/static.lob.com/assets/cards/pts_back.pdf"
37 )
38
39 try:
40 # Create the postcard
41 api_response = api_instance.create(postcard_editable)
42 print(api_response)
43 except lob.ApiException as e:
44 print("Exception when calling PostcardsApi->create: %s\n" % e)