Step 3: Create the API

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": "[email protected]", "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": "[email protected]",

    "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.

Last updated