LogoLogo
HomeCommunityLangstack.comCreate free account
  • 🤝Welcome
  • 🙌Support
  • 💡Get started
    • 📕Learn Langstack
      • Introduction to Langstack
        • Application templates
        • Storage frameworks
        • Account administration
      • Basics and essentials
        • What is an API gateway?
        • How to work with an API gateway
        • What is an Entity?
        • What is an Action box?
          • How to create and work with Action boxes
          • How to perform search in Actions
        • What is an Action?
          • How to create and work with Actions
          • Error propagation
          • Actions in Langstack applications
        • What is a Data type?
          • Simple Data types
        • What is a Variable?
          • Naming rules of a Variable
        • What is a Function?
          • Working with Functions
        • Navigating to a Variable or a Function
        • Implicit Type Conversion (ITC)
        • Explicit Type Conversion
        • Implicit and Explicit Type Conversion for Json
        • Next Steps
      • User management
        • What is a Privilege?
        • What are Groups?
        • What are Users?
      • Introduction to REST API
        • API Name
        • API Group name
        • Request and Response body
          • Request body
          • How to create and work with a Request body
          • Response body
          • How to create and work with a Response body
        • Query strings
          • How to create and work with Query strings
        • Headers
          • How to create and work with Headers
        • Path parameter
        • Create your first API: "Hello World!"
          • Working with API options
        • Exercise 1: GET REST API & Return Response Object
          • Step 1: Create API
          • Step 2: Test the API
        • Exercise 2: Delete a published API
        • Next Steps
      • Introduction to Entities
        • Fields
        • Records
        • Relations
        • Options for an Entity
        • Exercise 1: Customer Accounts and Activities
          • Customer accounts
            • Step 1: Create the Customers Entity
            • Step 2: Create the API
            • Step 3: Update entity through API
          • Customer Activities
            • Step 1: Create the Activities entity
            • Step 2: Create a “1 to Many” relation
            • Step 3: Create the API
            • Step 4: Update entity through API
        • Exercise 2: Customer Records
          • Step 1: Create the API
          • Step 2: Test the API
        • Next Steps
      • Programming with Entities
        • Create
        • Read
        • Update
        • Delete
        • JXPResponse
        • Next Steps
      • Using Triggers
        • After Create Trigger
        • After Update Trigger
        • After Delete Trigger
        • Exercise: Entity & Entity triggers
        • Step 1: Define “After Create” Trigger
        • Step 2: Define “After Update” Trigger
      • Connectors
        • Create a connector
        • SFTP Connector
        • MySQL Connector
        • Next Steps
      • Introduction to ETL pipeline
        • Create an ETL pipeline
        • Data Formats in ETL pipeline
          • Reader
          • Writer
          • Field mapping
        • Shared variables for ETL pipeline
        • ETL functions execution sequences overview
        • Displaying Functions
        • How to perform Search in ETL pipeline
        • Exercise 1: Skip Customer records
          • Step 1: Create the ETL pipeline
          • Step 2: Skip records based on Customer_ID
          • Step 3: Store skipped records in a list
          • Step 4: Store the Skipped Customer record
        • Exercise 2: ETL pipeline, CSV source & FTP Connector
        • Exercise 3: ETL pipeline, Database Source & MySQL Connector
        • Exercise 4: ETL pipeline, CSV Source & FTP Connector using Sections
          • Step 1: Create the ETL pipeline
          • Step 2: Reformat the Join_Date Values and define added fields
      • Multiple Executions, Time Duration, Linked App and Execution Status
        • Skip execution while in progress
        • Time duration settings
        • Linked App
        • Options for Delay Types
        • Execution status
      • Validation pipeline
        • Sequence of Validation pipeline
        • Exercise: Customer Information
          • Step 1: Create a Validation pipeline
          • Step 2: Create the API gateway
          • Step 3: Test the Validation pipeline
      • Introduction to Process
        • Create a process
        • Shared variables for a process
        • Exercise: Customer Anniversary Email Activity
          • Step 1: Check if the join date matches the current date
          • Step 2: Test the Process
      • Introduction to Flows & Flow components
        • What is a Flow?
        • What is a Flow component?
          • What is a Flow component Event?
        • Exercise 1: Customer Anniversary Email
          • Step 1: Create the Flow component
          • Step 2: Create the Flow
          • Step 3: Trigger the Flow
          • Step 4: Check records in the target entity
        • Exercise 2: Store list of customers
          • Step 1: Create the Flow component
          • Step 2: Create the Flow
          • Step 3: Create the API
    • 🌍Tour of Langstack (coming soon)
  • 📘In depth learning
    • 📖User Manual (coming soon)
    • 🔗Connectors
      • MS-SQL connector
        • Data type conversions between Langstack and MSSQL
        • Handling data loss in data type conversions
        • Setting up MS-SQL connector
        • MS-SQL connector as Reader and Writer
        • Using MS-SQL connector in ETL pipeline
          • MS-SQL connector as a source
          • MS-SQL connector as a destination
      • Google Drive connector
        • Set up Google Drive Connector
        • Adding Google Drive path in ETL pipeline Streams
        • Setting up GCP Account, GCP Project, API Enablement, and Credentials (Prerequisites)
          • OAuth 2.0 Client Credentials
          • Service Account Key Credentials
          • API Key Credentials
          • Authorization through Redirect URLs
        • Using Google Drive connector in ETL pipeline
          • Specifying file or folder paths
            • Direct file link
            • Folder link and file name
            • Folder path and file name
            • Folder path excluding file name
            • Folder path including file name
          • Google Drive connector as a source
          • Google Drive connector as a destination
      • AWS connector
        • Introduction
        • Set up AWS S3 Connector
          • OAuth 2.0 Client Type
          • Access Key
          • Public
        • Setting up AWS Account
          • Retrieve Client ID and Client Secret
        • Set up Amazon Web Services (Cognito) Console
          • Retrieve Identity Pool Id
          • Manage Permissions for Roles
          • Adding Redirect URL in Amazon Developer Console
          • User Consent for OAuth 2.0 Client through Login with Amazon
          • Retrieve Access Key Credentials
        • Creating a bucket in AWS
        • Using S3 connector in ETL pipeline
          • Specifying paths
          • Examples
            • AWS S3 connector as a source
            • AWS S3 connector as a destination
      • OneDrive connector
        • Set up OneDrive Connector
        • Setting up Microsoft Azure Account
        • Add URL to Authorized Redirect URLs
        • User Consent for Establishing OneDrive Connection
        • Usage of OneDrive Connector in ETL pipeline
          • Examples
          • OneDrive connector as a source
          • OneDrive connector as a destination
      • Dropbox connector
        • Set up Dropbox Connector
        • Setting up Dropbox Account
        • Add URL to Authorized Redirect URLs
        • User Consent for Establishing Dropbox Connection
        • Usage of Dropbox connector in ETL pipeline
          • Dropbox connector path settings
          • Examples
            • Dropbox connector as a source
            • Dropbox connector as destination
  • 🗃️Use Cases (Coming soon)
    • Use Case 1
    • Use Case 2
    • Use Case 3
Powered by GitBook
On this page
  1. Get started
  2. Learn Langstack
  3. Introduction to Entities
  4. Exercise 1: Customer Accounts and Activities
  5. Customer accounts

Step 2: Create the API

PreviousStep 1: Create the Customers EntityNextStep 3: Update entity through API

Last updated 2 years ago

Once the Entity is created, configure an API to create customer account records and store them in the “UserName_Acc_customers” Entity created in .

  • To go to APIs, click “API” under the “APIs and integration” menu on the left side panel.

  • To create a new API, click the [+ API] button.

  • The New API page displays with the Details tab preselected. To define the API, add the following information:

    1. Enter the API name as “UserName_Acc_AddCustomer”. The name indicates that a customer has been added.

    2. Select the API method as “POST”. This defines that the API will be posting or sending data.

    3. Optionally add a description for the API.

  • Create a new Group Name, "UserName", by clicking [+].

  • Add constant text for API Paths as “acc” and “addcustomer”. Each of both parameters displays in a blue bubble.

  • The URL for the API is generated.

  • Enable “public documentation”. This defines the API documentation to be accessed publicly.

  • To define the Request body and response body details, go to the “Inputs & outputs” tab.

  • To define the Request body, go to the Inputs & outputs tab>Request body section. Click it to expand the already created Request body. It is defined with the following information:

    1. Label the Request body as “requestJsonCreateCustomer”.

    2. Content type from the list of values is selected as “application/json”. This defines the type of content in the request.

    3. Character set is selected as “Universal (UTF-8)”.

    4. Optionally enter a description for the “Request body”. (This is used in the API documentation.)

    5. To add a sample JSON from an entity, select the entity “UserName_Acc_customers” from the “Copy sample json from” drop-down menu (this is the Entity created in Step 1).

    6. A json object is populated representing all the created fields in the entity “UserName_Acc_customers”.

  • To define the Response body, go to the Inputs & outputs tab>Response body section and click it to expand it. A Response body is already created and defined with the following information:

    1. By default, the name for the response body is “defaultResponseJsonBody”. For this exercise, keep the response body name as is.

    2. The Content type from the list of values is selected as “application/json”. This defines the type of content in the response.

    3. The Response Code is selected as “200 OK”.

    4. Character set is selected as “Universal (UTF-8)”.

    5. Optionally add a description for the “Response body” (This is used in the API documentation).

    6. To define a sample Json for the response, type the following json object: { "status": "success or failed", "errorcode": "0", "message": "The response of creating the entity record.", "details": [] }

This object indicates that: - The status is “success” or “failed”. - The error code is zero (0). - The message displayed is “The response of creating the entity record.” - The details will be a list of values as identified by the two square brackets “[].”

  • To define the Target Entity for this API, go to the “Target Entities” tab. Target entities are the entities that the Actions in this API can process data into i.e., perform add, update or delete upon. To create a new target entity, click [+ Target entity].

  • To define the Target entity for storing the created record:

    1. Select Target entity as “UserName_Acc_customers” (created in Step 1).

    2. Keep “Select a default Validation pipeline” as is. If a Validation pipeline needs to be applied to the data before storing in an entity, the relevant Validation pipeline can be selected in this field. In this exercise, no Validation pipeline is applied.

    3. “Show in API gateway” toggle button is enabled by default. This must be enabled so that the API is visible to the API gateway through which it can process the information into the entity.

  • To see the default variables created for an API, go to the “Variables” tab. The following two (2) Read Only variables are predefined:

    1. Variable Name: “Request”, Data Type: “WebRequest” This variable contains the Web Request received.

    2. Variable Name: “Response”, Data Type: “WebResponse” This variable contains the Web Response sent.

  • To create Actions for this API, go to the “Code” tab. By default, an “Action box” is already created with the description of the “Action box” as “OnExit”. To change the label of the “Action box”, double click the description and label the “Action box” as “Add request to Entity Acc_customer”. (In this Action box, the records will be updated in the Target entity based on the request received.)

  • Expand the "Action box", an Action called “API Respond” is already added. Notice the variable as “defaultResponseJsonBody”.

    Remove the existing Action “API Respond”. (It will be added later after all the Actions are defined as no Action is executed after “API Respond”.)

  • To define the variables, go to the “Variables” tab of the “Action box”. The variables created here will cover the scope of the “Action box”. To create a new variable, click the [+ Variable] button.

  • To contain the values for the fields of the desired entity in a record, define the variable as follows:

    1. Enter Variable Name as “Acc_customers”.

    2. Select Data Type as the Entity “UserName_Acc_customers”.

  • To define the Actions, click on the “Code” tab in the “Action box” and add an Action.

  • To update the variable “Acc_customers” with details (from the json object) for the customer fields defined in the Entity “UserName_Acc_customers” , define the first Action as follows:

    1. Select Action as “Update Entity fields from json”.

    2. Select the Target variable as “Acc_customers”.

    3. Select Source variable as Variables>Request>requestJsonCreateCustomer. It displays as “Request.requestJsonCreateCustomer”.

    4. Select the checkbox “Unset missing fields”. By this setting, if the field is not found in the json request, the Action will set the field in the target variable (“Acc_customer” in this case) as unset.

  • To define all the Actions, add six (6) more Actions by clicking (+) the button.

  • To update the value of “Customer_Value” received via “Request Body” to “zero (0)”, define the second Action as follows:

    1. Select Action as “Update Variable”.

    2. Select Target Variable as Acc_customers>Customer_Value. It displays as “Acc_customers.Customer_Value”.

    3. Add Value as “0” (without quotes) and press Enter.

  • To update the value of “Rating” received via “Request Body” to “one (1)”, define the third Action:

    1. Select Action as “Update Variable”.

    2. Select Target variable as “Acc_customers.Rating”.

    3. Add Value as “1” (without quotes) and press Enter. It displays in a blue bubble.

  • To check if the “Join_Date” value is received in the “Request Body”, define the fourth Action such that if the Join Date is received, it will display the date as per the given value in Join Date, else it will update the date to current date and time.

    1. Select Action as “Condition action”.

    2. Add Condition Name as “check join date”.

  • Under the Criteria tab, add 2 Criteria bars by clicking the (+) button.

  • To check if a value for the “Join_Date” has been received, define the first Criteria bar as follows

    1. Select Source as Variables>Acc_customers>Join_Date. It displays as “Acc_customers.Join_Date”.

    2. Select the Operator as “Is Set”.

  • To check if a value for the “Join_Date” is not equal to zero (0), define the second Criteria bar to convert the value of “Join_Date” from string data type to integer and check if the value is not equal to zero ‘0’.

    1. Select Source as Variables>Acc_customers>Join_Date>toInteger(). It displays as “Acc_customers.Join_Date.toInteger()”.

    2. Select the Operator as “Is Not Equal”.

    3. Enter the Value as “zero (0)”.

  • The AND logical operator displays indicating that both of these criteria must be validated before execution of the “Code” tab in the Condition action.

  • To define the Actions in case the return as “False”, go to the Code tab>On False section of the “Condition action”.

  • Add an Action to update the value of the “Join_Date” to current Date and Time if the “Join_Date” is not received. Define the Action:

    1. Select Action as “Update Variable”.

    2. Select Source as Acc_customers>Join_Date. It is displayed as “Acc_customer.Join_Date”.

    3. Select Value as Functions>DateTime>Now(). It is displayed as “DateTime.Now()”. The value will be of the current date and time.

  • To update the information received in the EntityCreationResponse (Json object) to a record in the Entity “UserName_Acc_customers”, after the Condition action define the fifth Action as follows:

    1. Select Action as “Create Entity record”.

    2. Select Source as “EntityCreationResponse”. The entity is created in this response variable.

    3. Select the Entity variable as “Acc_customers”. This entity variable is the source from which the values are taken.

  • To convert the information received in “EntityCreationResponse” to Json and update it in the default Response, define the sixth Action as follows:

    1. Select Action as “Updade Variable”.

    2. Select Target variable as Response>defaultResponseJsonBody. It displays as “Response.defaultResponseJsonBody”.

    3. Select the Entity variable as Variables>EntityCreationResponse>toJson(). It displays as “EntityCreationResponse.toJson()”.

  • To send response through the predefined response variable, define the last Action as follows:

    1. Select Action as “API Respond".

    2. Set Response as “defaultResponseJsonBody”.

  • After all the Actions are created, the “Code” tab in the Action box should look as follows:

  • To save the API, click the [Save] button.

  • To publish the API, click the [Publish] button.

  • To define the API gateway, go to the Details tab and add the API gateway for this API as “UserName_Acc_AddCustomer”. Save the API again.

  • To save the API again, click the [Save] button.

  • In the “Details” tab and on the right-hand side, ensure the API is enabled.

💡
📕
Step 1