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 Flows & Flow components
  4. Exercise 2: Store list of customers

Step 3: Create the API

PreviousStep 2: Create the FlowNextTour of Langstack (coming soon)

Last updated 2 years ago

Create an API to trigger the Flow to create records from the list of customers and store them in the “UserName_Acc_customers” Entity created in Step 1.

  • 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_async_addlistofcustomers”. The name indicates that a customer has been added.

    2. Select the API method as “POST”. This defines that the API will post or send data.

    3. Optionally add a description for the API.

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

    1. Enter the Group name as “UserName”.

    2. Enter the Group base URL as “UserName”.

    3. To save the Group name details, click [Save].

  • Add API Paths as “async” and “addlistofcustomers”. Each parameter displays in a blue bubble.

  • The URL for the API is generated.

  • 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. By default, the name for the request body is “defaultRequestJsonBody”. For this exercise, label it 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 define the json sample for the request, add the following Json:

    [{ "Address_Line_1": "first Street", "City": "", "Customer_Value": 5, "Country": "USA", "Email": "JaneDoe@mail.com", "First_Name": "Jane", "IsActive": true, "Join_Date": "2021-09-15", "Last_Name": "Doe", "Phone": "1237865", "Rating": 1000, "Zip_Code": "45"

    }]

  • 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”.

    2. Keep “select a default validation” 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 gateways” 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 “Action box” label, double click the description and label the Action box as “create records for list of customers”. In this “Action box”, the records will be updated in the entity “UserName_Acc_customers” based on the request received.

  • Click on the arrow on the top right corner of the “Action box” to expand it. In the “Code” tab, an Action called “API Respond” is already added. Notice the variable as “defaultResponseJsonBody”. Remove this action for now.

  • First, the variables need to be defined and initialized. To define the variables, go to the “Variables” tab 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 “triggerCustomerRecord”.

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

  • To contain the values for the Json fields received in the request, define the variable as follows:

    1. Enter Variable Name as “detailsJS”.

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

  • To define the Json sample (layout in which the list of customers will be received in the request), click the [Sample] button.

  • Add the following Json sample in the Sample Schema View: { "customerslist": [{ "Address": "first Street",

    "City": "",

    "Customer_Value": 5,

    "Country": "USA",

    "Email": "JaneDoe@mail.com",

    "First_Name": "Jane",

    "IsActive": true,

    "Join_Date": "2021-09-15",

    "Last_Name": "Doe",

    "Phone": "1237865",

    "Rating": 1000,

    "Zip_Code": "45" }] }

    To save the Sample Schema, click the [Save] button.

  • To define the actions for this API, go to the “Code” tab of the Action box and add three (3) Actions.

  • Define the first three actions to acknowledge the request and to send the response that the request is queued. To send the response code, redefine the first, existing first Action as follows:

    1. Select Action as “Update Variable”.

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

    3. Enter Value as “200” and press Enter.

  • To send the response message, add the second Action and define it as follows:

    1. Select Action as “Update Variable”.

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

    3. Enter Value as “Your request is now queued for processing.” and press Enter.

  • To send the response status, add the third Action and define it as follows:

    1. Select Action as “Update Variable”.

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

    3. Enter Value as “Request Queued” and press Enter.

  • Once the response has been sent, the created Flow will be triggered to create the customer record. To trigger a Flow, it is mandatory that an entity record is loaded.

  • To create the record to load and ensure it does not get deleted, for this exercise, go to the “UserName_Acc_customers” entity and create a record as follows:

    1. Address: DO NOT DELETE

    2. City: DO NOT DELETE

    3. Country: DO NOT DELETE

    4. Customer_ID: (autogenerated)

    5. Customer_Value: 1

    6. DayMonthJoinDate: (current day and month)

    7. First_Name: DO NOT DELETE

    8. IsActive: true

    9. Join_Date: (current day and month)

    10. Last_Name: DO NOT DELETE

    11. Phone: DO NOT DELETE

  • To load the entity record for triggering the Flow, go to the API, add the fourth Action, and define it as follows:

    1. Select Action as “Load Entity record”.

    2. Select Target Value as “triggerCustomerRecord”.

    3. Click on the Setup Criteria button to define the settings for this Action.

  • To define the Setup criteria for the entity record:

    1. Select Order by as “First_Name”.

    2. By default, the “Descending” option is selected. Keep it as is.

    3. Add a match key by clicking the [+ Match key] button.

  • To match the First_Name field of the entity to “DO NOT DELETE” text, define the match key as follows:

    1. Select Field as “First_Name”.

    2. Enter Source as “DO NOT DELETE”.

    3. To save the settings, click the [Save] button.

  • To update the request into the Json field to be loaded with the entity while triggering Flow, add and define the fifth Action as follows:

    1. Select Action as “Update Variable”.

    2. Select Target Value as detailsJS>customerslist. It displays as “detailsJS.customerslist”.

    3. Enter Value as Variables>Request>defaultRequestJsonBody. It displays as “Request.defaultRequestJsonBody”.

  • To trigger the Flow, add and define the sixth Action with the entity variable and Json sample as follows:

    1. Select Action as “Trigger Flow”.

    2. Select Flow as “UserName_createlistofcustomers”. Select Entity variable as Variables>triggerCustomerRecord. It displays as “triggerCustomerRecord”.

    3. Select Json as Variables>detailsJS. It displays as “detailsJS”.

  • To send the API response, add the last Action and define it as follows:

    1. Select Action as “API Respond”.

    2. Select Response body as “defaultResponseJsonBody”.

  • 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_async_addlistofcustomers”. Save the API again.

  • Ensure the API is enabled in the “Details” tab on the right-hand side.

  • To test the API, click the [Test] button.

  • In the Test Console:

    1. Add the values of the list of customers.

    2. Enable the [Entity actions] toggle button.

    3. Click [Test API].

  • To see the Response, go to the Body section in the Test Console. The response message displays stating that the request is queued for processing.

💡
📕