Application Integration provides multiple types of triggers like API Trigger, Cloud Pub/Sub Trigger, Schedule Trigger and a few more. The most commonly used among them is API Trigger. More details on how it can be used in an integration can be found here. This trigger provides a way to execute integration via Application Integration API.
Here are some of the ways to trigger an integration with API Trigger:
Test button is directly available on the integration designer page.
On clicking on this button, a form pops up in which you will need to provide values for input variables. You can choose to run with default values or provide custom values.
Once the TEST INTEGRATION button is clicked, the integration gets executed and the response pops up with the output variables if any.
Application Integration APIs also provide an option to execute the integration by calling HTTP endpoint.
Note: This will need the end user to have the Application Integration Invoker role in the gcp project where integration exists.
For example, we want to execute the ExampleIntegration that gets created while provisioning Application Integration in a GCP project. A simple curl call to the execute API can be used:
https://integrations.googleapis.com/v1/projects/<project_id>/locations/<location>/integrations/ExampleIntegration-EcomOrderProcessing:execute
With request body :
{"trigger_id":"api_trigger/ecom-order-processin_API_1"}
This will execute the ExampleIntegration with default values to the input variables.
A complete example of curl command will look like this:
curl -v -X POST -H "Content-Type: application/json" -d
'{"trigger_id":"api_trigger/ecom-order-processing_API_1"}'
'https://integrations.googleapis.com/v1/projects/<project_id>/locations/<location>/integrations/ExampleIntegration-EcomOrderProcessing:execute' -H "Authorization: Bearer $(gcloud auth print-access-token)"
If the integration has to be executed with custom inputs, here is an example:
curl -v -X POST -H "Content-Type: application/json"
'https://integrations.googleapis.com/v1/projects/<project_id>/locations/<location>/integrations/ecom-order-processing:execute' -H "Authorization: Bearer $(gcloud auth print-access-token)" -d
'{ "triggerId": "api_trigger/ecom-order-processing_API_1",
"inputParameters": {
"orders_request": {
"jsonValue": "{\n \"order_no\": \"12345\",\n \"buyer_id\": \"raambo\",\n \"line_items\": [{\n \"line\": 1.0,\n \"sku\": \"tr100\",\n \"vendor\": \"Internal\",\n \"quantity\": 1.0,\n \"price_per_unit\": 10.0\n }, {\n \"line\": 2.0,\n \"sku\": \"tbz\",\n \"vendor\": \"External\",\n \"quantity\": 24.0,\n \"price_per_unit\": 2.0\n }]\n}"
}
}
}'
The v1 API needs input parameters of type json in stringified json format.
However, v2 APIs(currently in preview mode) can be provided with the input parameters as json itself.
For this, create a file called input.json and save the following json:
{
"orders_request" : {
"order_no": "12345",
"buyer_id": "raambo",
"line_items": [{
"line": 1.0,
"sku": "tr100",
"vendor": "Internal",
"quantity": 1.0,
"price_per_unit": 10.0
}, {
"line": 2.0,
"sku": "tbz",
"vendor": "External",
"quantity": 24.0,
"price_per_unit": 1.0
}]
}}
Now the same integration can be executed with following command:
curl -v -X POST -H "Content-Type: application/json" -d @input.json 'https://integrations.googleapis.com/v1/projects/<project_id>/locations/<location>/integrations/ExampleIntegration-EcomOrderProcessing:execute?trigger_id=api_trigger/ecom-order-processing_API_1' -H "Authorization: Bearer $(gcloud auth print-access-token)"
An integration can also be executed asynchronously by using the similar command with schedule API instead of execute. You can find more details here.
If a service account has access to execute the integration, the end user/system can impersonate the service account to execute the integration. But for that, it should have the ServiceAccountTokenCreator role on the service account which is being impersonated. The following command will work with right permissions:
curl -v -X POST -H "Content-Type: application/json" -d
'{"trigger_id":"api_trigger/ecom-order-processing_API_1"}'
'https://integrations.googleapis.com/v1/projects/<project_id>/locations/<location>/integrations/ExampleIntegration-EcomOrderProcessing:execute' -H "Authorization: Bearer $(gcloud auth print-access-token) --impersonate-service-account=<service_account>"
If you are an Apigee user, you can also set up Apigee Proxy to call integration. Follow these docs for the setup guide:
Solved! Go to Solution.
Thanks for posting this @salonijuneja 👏
Thanks for posting this @salonijuneja 👏