I am writing a Google cloud function which calls Application Integration API trigger but getting an error:
Traceback (most recent call last):
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/flask/app.py", line 1463, in wsgi_app
response = self.full_dispatch_request()
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/flask/app.py", line 872, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/flask/app.py", line 870, in full_dispatch_request
rv = self.dispatch_request()
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/flask/app.py", line 855, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
File "/layers/google.python.pip/pip/lib/python3.9/site-packages/functions_framework/__init__.py", line 134, in view_func
return function(request._get_current_object())
TypeError: trigger_api() takes 0 positional arguments but 1 was given
Please find the below code:
import requests
def trigger_api():
PROJECT_ID = "test"
LOCATION = "europe-west1"
INTEGRATION_ID = "poc-callTrigger"
TRIGGER_ID = "api_trigger/poc-callTrigger_API_1"
API_URL = f"https://integrations.googleapis.com/v2/projects/{PROJECT_ID}/locations/{LOCATION}/integrations/{INTEGRATION_ID}:execute"
RESOURCE_DATA = {"data": {"id": "12345678"}}
headers = {"Content-Type": "application/json"}
request_body = {
"triggerId": TRIGGER_ID,
}
response = requests.post(API_URL, headers=headers, json=request_body)
if response.status_code == 200:
return response.json()
else:
raise Exception(f"Error triggering API: {response.text}")`
I also want to understand if any authentication is required if both cloud function and integration are deployed in the same project. If yes how can I dynamically pass it?
My expectation is to resolve this error, authentication and if there are any changes required in the code.