Not able to call Application Integration configured with API trigger

I have an integration created which has invoking as API Trigger. I am able to test the flow via console using the Test button as below:

Nitin_Rawat_0-1696959196110.png

But when am trying to do the same via postman am facing some issues where I need some help/Guidance.

So I went through this article and setup the request in postman via curl

https://cloud.google.com/application-integration/docs/configure-api-trigger#syntax

Questions

1> My integration has an input variable and am not sure how to provide that, the article gives the curl as below : I changed the dummy stuff with the new one and actually it hits the integration but the input variable is not passed. So the question is what is the syntax to pass the input variable?

curl -X POST \
    -H "authorization: Bearer $(gcloud auth print-access-token)"
    -H "Content-Type: application/json" \
    -d '{"trigger_id":"api_trigger/test_API_1"}' \
    "https://us-east1-integrations.googleapis.com/v1/projects/demo-project/locations/-/integrations/-:execute"

2> For the authorization header, I passed it like Bearer value,  where this value I got via using gcloud sdk shell by first activating a Service account and then manually running gcloud auth print-access-token and then copied that token and put it in value above. But this is a manual process and I need to know that is there a way where this token can be generated via a gcp API call or some other better automated way?

3> The API trigger I believe just triggers the flow, is it possible to make the complete flow synchronous and return the final flow response(preferably a json) to the postman initial call(Trigger call)?

 

Solved Solved
1 5 583
2 ACCEPTED SOLUTIONS

You are correct.  When you invoke the API Trigger, you can specify whether it is Async or Sync.  If you use the Sync option, it will return a response to the client and you can specify which variables you want to send back in the response payload by checking the box "Use as an Output variable" on the variable's detailed configuration.  The integrations/execute API is Synchronous.  The integrations/schedule API is Asynchronous.

Here is a sample curl command from this tutorial that shows the payload structure you must use for v1...looks like you beat me to it and figured this out already!  Nicely done... Note the "inputParameters" property, and you have to specify the data type of the parameter (see: "string_value" property followed by the actual value)  :

curl -v -X POST -H "Content-Type: application/json" 'https://integrations.googleapis.com/v1/projects/connectors-ip-test/locations/us-central1/integrations/api-fulfillment-integration:execute' -H "Authorization: Bearer $(gcloud auth AUTH_PROFILE)" -d  '{ "triggerId": "api_trigger/api-fulfillment-integration_API_1", "inputParameters": { "customer_id": {"string_value": 1}, "location" : {"string_value" : "US"}} }'

 The data types (ie: StringValue, etc..) are defined here as ValueTypes in the API Documentation.

Are you good with the Token generation steps through gcloud commands now?

View solution in original post

Here is the documentation on how to get access token from Googles OAuth endpoints. The steps described here are being done by gcloud transparently.

https://developers.google.com/identity/protocols/oauth2#2.-obtain-an-access-token-from-the-google-au...

Here are step by step instructions on using different client types (including http) to get the tokens:

https://developers.google.com/identity/protocols/oauth2/web-server#httprest

Finally, there's an oauth playground that you can  use which helps walk you through some of this.

https://developers.google.com/oauthplayground/

 

 

View solution in original post

5 REPLIES 5

Hi @Nitin_Rawat,

Welcome to Google Cloud Community!

To pass an input variable to an API trigger in Application Integration, you can use the following syntax:

{
  "trigger_id": "api_trigger/test_API_1",
  "input_variables": {
    "input_variable_name": "input_variable_value"
  }
}

To generate an access token via a GCP API call, you can use the following steps:

  1. Install the Google Cloud SDK.
  2. Authenticate with the Google Cloud SDK using the following command:
gcloud auth login
  1. Set the project ID that you want to use:
gcloud config set project PROJECT_ID
  1. Generate an access token using the following command:
gcloud auth print-access-token
  1. Copy the access token and use it in the Authorization header of your Postman request.

It is not possible to make the complete flow synchronous and return the final flow response to the Postman initial call. API triggers are asynchronous, meaning that they trigger the flow without waiting for it to finish. This allows the flow to run in the background without blocking the Postman request.

Thanks

Thanks Christian for replying to the thread.

For the input variable, the suggested way does not work for me but what worked is below way which I found here

 
{
  "trigger_id": "api_trigger/test_API_1",
  "inputParameters": {
    "BankAccountData": {"stringValue":"Sample Value"}
  }
}
 But I looked into it further and understood that the  way you suggested is for V2 version of the API and I am using V1 so that is why it did not worked for me but it is the right way for V2 so thanks for providing it. I will use your way when I switch to V2 of the API.
 
=============================Bearer Token==============================
For the auth token the provided steps are via gcloud and I also did the same thing but this is manual way and my question was around some way to do it via Rest API call(some kind of token generation api) to generate a token against a service account. If it is possible can you please pass the curl?
 
==============================Synchronous==============================
I figured that actually the API trigger are Synchronous in nature:
Nitin_Rawat_0-1697154320527.png

 

 
 

You are correct.  When you invoke the API Trigger, you can specify whether it is Async or Sync.  If you use the Sync option, it will return a response to the client and you can specify which variables you want to send back in the response payload by checking the box "Use as an Output variable" on the variable's detailed configuration.  The integrations/execute API is Synchronous.  The integrations/schedule API is Asynchronous.

Here is a sample curl command from this tutorial that shows the payload structure you must use for v1...looks like you beat me to it and figured this out already!  Nicely done... Note the "inputParameters" property, and you have to specify the data type of the parameter (see: "string_value" property followed by the actual value)  :

curl -v -X POST -H "Content-Type: application/json" 'https://integrations.googleapis.com/v1/projects/connectors-ip-test/locations/us-central1/integrations/api-fulfillment-integration:execute' -H "Authorization: Bearer $(gcloud auth AUTH_PROFILE)" -d  '{ "triggerId": "api_trigger/api-fulfillment-integration_API_1", "inputParameters": { "customer_id": {"string_value": 1}, "location" : {"string_value" : "US"}} }'

 The data types (ie: StringValue, etc..) are defined here as ValueTypes in the API Documentation.

Are you good with the Token generation steps through gcloud commands now?

Thanks @shaaland for replying on this thread.

As suggested I went through the schedule API and found exactly what I was looking for, specially the capability of executing the flow immediately(by passing past same day scheduleTime) or at a scheduled future time makes it more favorable for my scenario.

 

For the bearer token, I am well aware of how to generate it via GCLOUD commands but what am looking for is how to get that bearer token against a service account without using GCLOUD commands. If it is at all feasible then please help in guiding me.

Here is the documentation on how to get access token from Googles OAuth endpoints. The steps described here are being done by gcloud transparently.

https://developers.google.com/identity/protocols/oauth2#2.-obtain-an-access-token-from-the-google-au...

Here are step by step instructions on using different client types (including http) to get the tokens:

https://developers.google.com/identity/protocols/oauth2/web-server#httprest

Finally, there's an oauth playground that you can  use which helps walk you through some of this.

https://developers.google.com/oauthplayground/