Modelling Customers in Duffel
Introduction
Associate your users with bookings and orders
Enable access to the Travel Support Assistant
Organise users into meaningful groups
Maintain consistent user information across the Duffel API
Allow Duffel to send confirmation and support emails if desired
Understanding Customer Users
JSON
{"data": {"id": "icu_0000AgZitpOnQtd3NQxjwO","email": "tony@stark.com","phone_number": "+14155550123","given_name": "Tony","family_name": "Stark","created_at": "2023-06-01T12:00:00Z","group": null}}
Understanding Customer User Groups
JSON
{"data": {"id": "usg_0000AgZitpOnQtd3NQxjwO","name": "Stark Industries","created_at": "2023-06-01T12:00:00Z"}}
Creating a Customer User
Shell
curl -X POST https://api.duffel.com/identity/customer/users \-H "Accept-Encoding: gzip" \-H "Accept: application/json" \-H "Content-Type: application/json" \-H "Duffel-Version: v2" \-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \-d '{"email": "tony@stark.com","phone_number": "+14155550123","given_name": "Tony","family_name": "Stark"}'
JSON
{"data": {"id": "icu_0000AgZitpOnQtd3NQxjwO","email": "tony@stark.com","phone_number": "+14155550123","given_name": "Tony","family_name": "Stark","created_at": "2023-06-01T12:00:00Z","live_mode": false,"group": null}}
Required and Optional Fields
email
is required and must be unique within a group (or among users without groups)given_name
andfamily_name
are requiredphone_number
is optional
Creating a Customer User Group
Shell
curl -X POST https://api.duffel.com/identity/customer/user_groups \-H "Accept-Encoding: gzip" \-H "Accept: application/json" \-H "Content-Type: application/json" \-H "Duffel-Version: v2" \-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \-d '{"name": "Stark Industries"}'
JSON
{"data": {"id": "usg_0000AgZitpOnQtd3NQxjwO","name": "Stark Industries","created_at": "2023-06-01T12:00:00Z"}}
Creating a Customer User within a Group
Shell
curl -X POST https://api.duffel.com/identity/customer/users \-H "Accept-Encoding: gzip" \-H "Accept: application/json" \-H "Content-Type: application/json" \-H "Duffel-Version: v2" \-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \-d '{"email": "pepper@stark.com","phone_number": "+14155550124","given_name": "Pepper","family_name": "Potts","group_id": "usg_0000AgZitpOnQtd3NQxjwO"}'
JSON
{"data": {"id": "icu_0000AgZpQrZjNcR4Mqklwx","email": "pepper@stark.com","phone_number": "+14155550124","live_mode": false,"given_name": "Pepper","family_name": "Potts","created_at": "2023-06-01T12:15:00Z","group": {"id": "usg_0000AgZitpOnQtd3NQxjwO","name": "Stark Industries"}}}
Using Customer Users when Creating Orders
Shell
curl -X POST https://api.duffel.com/air/orders \-H "Accept-Encoding: gzip" \-H "Accept: application/json" \-H "Content-Type: application/json" \-H "Duffel-Version: v2" \-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \-d '{"data": {"users": ["icu_0000AgZitpOnQtd3NQxjwO"],"type": "instant","selected_offers": ["off_0000AgZitpOnQtd3NQxjwO"],"payments": [{"type": "balance","currency": "GBP","amount": "430.00"}],"passengers": [{"user_id": "icu_0000AgZitpOnQtd3NQxjwO","title": "mr","phone_number": "+14155550123","id": "pas_0000AgZpQrZjNcR4Mqklwx","identity_documents": [{"unique_identifier": "75209451","type": "passport","issuing_country_code": "US","expires_on": "2030-06-25"}],"given_name": "Tony","gender": "m","family_name": "Stark","email": "tony@stark.com","born_on": "1970-05-29"}],"metadata": {"internal_order_id": "avengers-123","mission": "conference"}}}'
users
array and as the user_id
in the passenger object), you:Associate the order with a specific user in your system
Enable that user to access this order through the Travel Support Assistant
Make it easier to track and manage orders for specific users
Using Customer Users when Creating Bookings
Shell
curl -X POST https://api.duffel.com/stays/bookings \-H "Accept-Encoding: gzip" \-H "Accept: application/json" \-H "Content-Type: application/json" \-H "Duffel-Version: v2" \-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \-d '{"data": {"users": ["icu_0000AgZitpOnQtd3NQxjwO"],"quote_id": "quo_0000AS0NZdKjjnnHZmSUbI","phone_number": "+14155550123","payment": {"three_d_secure_session_id": "3ds_0000AWr2Xs1Vp34gh5"},"metadata": {"customer_reference_number": "STARK001"},"loyalty_programme_account_number": "201154908","guests": [{"user_id": "icu_0000AgZitpOnQtd3NQxjwO","given_name": "Tony","family_name": "Stark"}],"email": "tony@stark.com","accommodation_special_requests": "Need large workbench space for technical projects"}}'
users
array and as the user_id
in the guest object provides the same benefits of user association and support access.Using Additional Customer Users
users
array:Shell
curl -X POST https://api.duffel.com/air/orders \-H "Accept-Encoding: gzip" \-H "Accept: application/json" \-H "Content-Type: application/json" \-H "Duffel-Version: v2" \-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \-d '{"data": {"users": ["icu_0000AgZitpOnQtd3NQxjwO","icu_0000AgZpQrZjNcR4Mqklwx"],"type": "instant","selected_offers": ["off_0000AgZitpOnQtd3NQxjwO"],"payments": [{"type": "balance","three_d_secure_session_id": "3ds_0000AWr2Xs1Vp34gh5","currency": "GBP","amount": "430.00"}],"passengers": [{"user_id": "icu_0000AgZitpOnQtd3NQxjwO","title": "mr","phone_number": "+14155550123","id": "pas_0000AgZpQrZjNcR4Mqklwx","identity_documents": [{"unique_identifier": "75209451","type": "passport","issuing_country_code": "US","expires_on": "2030-06-25"}],"given_name": "Tony","gender": "m","family_name": "Stark","email": "tony@stark.com","born_on": "1970-05-29"}],"metadata": {"internal_order_id": "avengers-123","mission": "conference"}}}'
A personal assistant is booking on behalf of an executive
A team leader needs access to team members' bookings
Family members need to access each other's travel information
Additional Management Options
Best Practices
Create Customer Users early: Create them when users register in your application, not just at booking time
Use meaningful group names: Choose names that reflect your business structure or customer segmentation, this is especially important if accessing the Travel Support Assistant
Associate all orders and bookings: Even if you don't immediately need the Travel Support Assistant, associating users with their orders creates a better foundation for the future
Keep user information updated: When your users update their contact information, be sure to update their Customer User records in Duffel too
Conclusion
Keep Learning
View their booking details
Make changes to their bookings
Get travel support and assistance
Access self-service options