Glyue User Docs
  • What is Glyue?
  • Tutorials
    • Start Here
    • Building a Single-Step Integration
      • 1. Creating the Integration
      • 2. Calling the External System
      • 3. Running the Integration
      • 4. Crafting the Output
    • Building a Multi-System Integration
      • 1. Connecting to the Core
      • 2. Field Mapping
      • 3. Running the Integration
    • Building an Event-Driven Integration
      • 1. Setting up the Mock CRM
      • 2. Receiving Inbound Requests
      • 3. Triggering the Integration from the CRM
    • Building an Email Integration
      • 1. Create and Configure the Integration
      • 2. Input Validation
      • 3. Get Story IDs from Hacker News
      • 4. Get Story Content
      • 5. Sending the Email
      • 6. Wrapping Up
      • 7. Extra credit
        • extra_credit.json
    • Building a RESTful CRUD Web Service
      • 1. Integration Setup
      • 2. Vault Setup
      • 3. Create Web Service Endpoints
      • 4. Execute Web Service Endpoints with Vault Methods
      • 5. Vault Code Examples and Explanation
    • Building a Retrieval API against FIS CodeConnect
      • 1. Integration Setup
      • 2. Service Request Setup
      • 3. Field Mapping Setup
      • 4. Integration and Service Request Hook Setup
      • 5. Testing the Integration
      • 6. Common Errors
    • What is Pre-Mapping?
      • Before you start
      • Bookmarks
      • Source and Targets
      • Field Mapping Status
      • Field Mapping Comments
      • Summary
  • How-To Guides
    • How to Run an Integration from Glyue
    • How to Invite New Users
    • How to Create a Value Mapping Set
    • How to Build and Deploy a Custom Frontend
    • How to Migrate an Integration
    • How to Set Up Single Sign On (SSO)
      • Glyue Setup
      • JumpCloud Setup
      • Azure Setup
      • Okta Setup
      • Glyue SAML Config Reference
    • How to Install the Glyue App for Zoom Contact Center
    • How to use the Vault
  • Reference
    • Integration Builder Page
    • Integration Anatomy
    • Integration Components
      • Integration
      • Service Request
      • Field Mapping
      • Value Mapping Set
      • Value Mapping
      • Validation Rule
      • Mask
      • Integration Config
      • Integration Engine Versions
    • Integration Lifecycle
    • Special Functions
      • add_run_label
      • callint
      • debug
      • end
      • get_namespace
      • humanize
      • import_helper
      • keep
      • list_files
      • map_value
      • open_glyuefile
      • open_vault
      • Data Manipulation Utilities
      • calladapter
    • Special Variables
      • __adapter_config__
      • input
      • parentint
      • retvalue
      • run_history_id
      • Iterables
        • fitem/fidx
        • sritem/sridx
        • vritem/vridx/vrmsg
    • Adapters
      • Generic HTTP Adapter
      • Email SMTP Adapter
    • Web Service Endpoints
    • Vault Reference
  • Glyue Platform Reference
    • Banking Core Connectivity Guide
    • Authentication
    • Permissions
      • Service Accounts
      • Organizations
    • Frontends
    • Idempotency Layer
    • Integration Scheduler
    • Governance Reports
    • Arbitrary Integration Request Content Support
    • Admin Components
    • Logging
  • ETL
    • Glyue ETL Overview
    • Data Connectors
    • Workflows
    • Run History
    • Scheduler
Powered by GitBook
On this page
  • Get All Customers
  • Get Customer By Id
  • Add a Customer
  • Update Customer
  • Delete Customer

Was this helpful?

  1. Tutorials
  2. Building a RESTful CRUD Web Service

5. Vault Code Examples and Explanation

To open the data vault, we use the open_vault function.

with open_vault('data') as vault: 
    # Get, insert, update, upsert, or delete vault data

Get All Customers

with open_vault('data') as vault:
    customers = vault.get('customers')

    if customers:
        output.payload = customers
    else:
        output.payload = "There are no customers in the data vault."

To retrieve the customers list in the data vault, we use the vault method get. Afterwards, we check if the customers list is empty. If it is not empty, we assign output.payload the customers list. Otherwise, we assign output.payload a confirmation message that there are no customers in the list.

Get Customer By Id

with open_vault('data') as vault:
    customers = vault.get('customers')
    customers = [customer for customer in customers if customer.id == input.path.id]

    if customers:
        output.payload = customers[0]
    else:
        output.payload = f'There are no customers with an id of: {input.path.id}'

To get a customer by Id in the data vault, we first use the vault method get to retrieve the customers list. Afterwards, we use a list comprehension to extract the customer from the customers list that has an Id that matches the id in input.path. At the end, we assign output.payload the customer's information in the form of a dictionary object or an error message if the customer was found.

Add a Customer

with open_vault('data') as vault:
    customers = vault.get('customers')
    customers.append(insert_customer.response.payload)
    vault.update('customers', customers)
    output.payload = { "id": insert_customer.response.payload.id }

To add a customer in the data vault, we first use the vault method get to retrieve the customers list. Afterwards, we append response.payload of insert_customer to the customers list and use the vault method update to save our changes to the customers list. At the end, we assign output.payload the Id of the new customer.

Update Customer

with open_vault('data') as vault:
    customers = vault.get('customers')
    customer = [customer for customer in customers if customer.id == input.path.id]

    if customer:
        customer[0].update(modify_customer.response.payload)
        vault.update('customers', customers)
        output.payload = customer[0]
    else:
        output.payload = f'There are no customers with an id of: {input.path.id}'

To update a customer in the data vault, we first use the vault method get to retrieve the customers list. Afterwards, we search for the customer via their Id. If the customer is found, we update the customer's information from response.payload of the service request modify_customer. At the end, we assign output.payload the customer's information in the form of dictionary object or an error message if the customer was not found.

Delete Customer

with open_vault('data') as vault:
    customers = vault.get('customers')
    previous_length = len(customers)
    customers = [customer for customer in customers if customer.id != input.path.id]

    if previous_length != len(customers):
        vault.update('customers', customers)
        output.payload = f"The customer with an id of {input.path.id} has been deleted."
    else:
        output.payload = f'There are no customers with an id of: {input.path.id}'

To delete a customer in the data vault, we first use the vault method get to retrieve the customers list. Afterwards, we record the current length of the customers list and we use a list comprehension to remove the customer from the customers list that has an Id that matches the id in input.path. If the length of the customers list has changed, we use the vault method update to save our changes to the customers list. At the end, we assign output.payload a confirmation message that the customer was deleted or an error message if the customer was not found.

Previous4. Execute Web Service Endpoints with Vault MethodsNextBuilding a Retrieval API against FIS CodeConnect

Last updated 11 months ago

Was this helpful?