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","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": "[email protected]","phone_number": "+14155550123","given_name": "Tony","family_name": "Stark","preferred_language": "fr"}'
JSON
{"data": {"id": "icu_0000AgZitpOnQtd3NQxjwO","phone_number": "+14155550123","given_name": "Tony","family_name": "Stark","created_at": "2023-06-01T12:00:00Z","live_mode": false,"group": null,"preferred_language": "fr"}}
Required and Optional Fields
emailis required and must be unique within a group (or among users without groups)given_nameandfamily_nameare requiredphone_numberis 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": "[email protected]","phone_number": "+14155550124","given_name": "Pepper","family_name": "Potts","group_id": "usg_0000AgZitpOnQtd3NQxjwO"}'
JSON
{"data": {"id": "icu_0000AgZpQrZjNcR4Mqklwx","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_0000AgZpQrZjNcR4Mqklwx"],"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": "[email protected]","born_on": "1970-05-29"}],"metadata": {"internal_order_id": "avengers-123","mission": "conference"}}}'
user_id on a passenger, or in the top-level users array for additional users), 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
user_id associates a Customer User with that passenger and allows them to manage the order. The top-level users array grants access to additional Customer Users, such as a travel arranger. When creating an order, do not include the same Customer User in both places. Sending users to the update order endpoint via PATCH replaces the additional-user list; omitting it leaves that list unchanged. This does not change any passenger's user_id or revoke their access, even if you send 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_0000AgZpQrZjNcR4Mqklwx"],"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": "[email protected]","accommodation_special_requests": "Need large workbench space for technical projects"}}'
user_id associates a Customer User with that guest and enables booking management, while the top-level users array grants access to additional Customer Users. Do not include the same Customer User in both places when creating a booking.Using Additional Customer Users
users array. In this example, Tony is the passenger and Pepper can also manage the order: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_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": "[email protected]","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
Set the preferred language: When creating a Customer User, you can set their preferred language. The user's preference will be shared with our travel support agents so we can provide support in their chosen language when available. If you'd like support in specific languages, please reach out to Sales
Conclusion
Keep Learning
View their booking details
Make changes to their bookings
Get travel support and assistance
Access self-service options