Execute Web Service Endpoints with Vault Methods
Last updated
Last updated
To execute any of the web service endpoints setup in the previous step (e.g. get all customers, get customer by Id, update customer, and delete customer), we must first write code in each of the connected integrations to open, read, and/or write to the data vault.
Log into Glyue, if necessary and navigate to the Build page. Select the get_all_customers
integration and add the following code in the Before Hook.
Assigning a value to output.payload
allows you to provide the desired content for the response body.
Navigate back to the Swagger page. Select the web service endpoint /rest/get_all_customers
. Click on the Try it out button and the Execute button.
You should receive text in the response body confirming that there are no customers in the data vault.
On the Run History page, you would noticed the integration get_all_customers
was executed because it is the integration connected to the endpoint /rest/get_all_customers
. Also, the input
displays the HTTP method and the full path or web service endpoint that was used to call this integration.
In the next step, we will execute this web service endpoint again after we add a new customer in the data vault.
In the add_customer
integration, we will create a service request and several field mappings to insert a customer in the data vault. The customer information will come from the body of a request and will contain the customer's first name, last name, birth date, and social security number.
Select the add_customer
integration to highlight it and right click it to display a context menu.
On the context menu, hover over Go To or Go to (New Tab) and select Service Request.
You will be redirected to the Service Request component on the Build page. On this page, click on the Add Row button at the bottom of the screen and fill in the fields with the following information for this service request.
Sequence - 1
System - ECHO
Service Name - N/A
Formula Variable - insert_customer
Click on the Save button below.
Click on the service request to highlight it and right click it to display a context menu again. On the context menu, hover over Go To or Go to (New Tab) and select Field Mapping.
You will be redirected to the Field Mapping component on the Build page. On this page, click on the Add Row button at the bottom of the screen and fill in the fields with the following information.
Sequence - 1
Field - id
Value - import uuid; retvalue = uuid.uuid4()
Value Type - str
Click on the Save button below.
The value of the id field contains code that generates a random UUID number.
Add the remaining field mapping rows for the first name, last name, birth date and social security as shown in the image below.
We are mapping the first name, last name, birth date, and social security number from input.payload
. The input.payload
contains information submitted in the body of a request.
Navigate back to the Swagger page and select the web service endpoint /rest/add_customer
. Click on the Try it out button and add a JSON object of customer information as shown in the image below. Click on the Execute button.
On the Run History page, you would see the integration add_customer
have the customer information that we submitted in the body of the request within input.payload
.
On the Run History Item, click on the insert_customer
request and you would see in the response the field mappings we added in the previous step. We will use response.payload
of the service request insert_customer
to add a customer in the data vault.
To add a customer in the data vault, navigate to the service request insert_customer
and add the following code in the After Execute Request Success Hook.
Navigate back to the Swagger page and execute the web service endpoint /rest/add_customer
again. You should receive the id of the customer in the response body.
Insert another customer as shown in the image below and execute the web service endpoint /rest/add_customer
.
Afterwards, execute the web service endpoint /rest/get_all_customers
. You should see both customers in the body of the response.
Navigate back to the Integration table on the Build page in Glyue and select the integration get_customer
. Add the following code in the Before Hook.
input.path
is the location where path parameter values can be accessed.
Navigate back to the Swagger page and select the web service endpoint /rest/get_customer
. Click on the Try it out button and add a valid id path parameter as shown in the image below.
Click on the Execute button. You should receive the customer's information in the form of a JSON object in the response body.
The following steps are similar to what we did to add a customer in the data vault. The major difference is we omit the id field because the customer Id should never change.
Create the following service request for the update_customer
integration.
Sequence - 1
System - ECHO
Service Name - N/A
Formula Variable - modify_customer
Click on the Save button below.
Next, create the following field mapping rows for the service request modify_customer
.
In the field mapping table, we are using the Call If column to omit or include a field and value in response.payload
based on the existence of the field in input.payload
.
Navigate back to the modify_customer
service request and add the following code in the After Execute Request Success Hook.
Navigate back to the Swagger page. Select the web service endpoint /rest/update_customer
and click on the Try it out button. Add a valid id path parameter and a new first name and last name in the body of the request as shown in the image below.
Click on the Execute button. You should receive the customer's information in the form of a JSON object with the first name and last name updated.
Navigate back to Integration table on the Build page in Glyue and select the integration delete_customer
. Add the following code in the Before Hook.
Navigate back to the Swagger page and select the web service endpoint /rest/update_customers
. Click on the Try it out button and provide a valid id path parameter as shown in the image below.
You should receive a confirmation message that the customer was deleted.