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:
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! Go to Solution.
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?
Here is the documentation on how to get access token from Googles OAuth endpoints. The steps described here are being done by gcloud transparently.
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/
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:
gcloud auth login
gcloud config set project PROJECT_ID
gcloud auth print-access-token
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"} } }
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.
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/