I had a scenario where I need to convert the curl command into a python snippet in order to trigger the API Trigger of Application Integration. This is the curl command:
curl -X POST -H "Content-Type: application/json" -d '{"trigger_id":"api_trigger/trigger_id", "inputParameters": {"partyName": {"stringValue": "sample_string"}}}' 'https://region-integrations.googleapis.com/v1/projects/project/locations/-/integrations/integrationName:execute' -H "Authorization: Bearer $(gcloud auth print-access-token)"
I have written the python snippet in this way:
url=âhttps://region-integrations.googleapis.com/v1/projects/project/locations/-/integrations/integrationName:executeâ
info = {
âclient_idâ: client_id,
âclient_secretâ: client_secret,
ârefresh_tokenâ: refresh_token
}
creds = Credentials.from_authorized_user_info(info=info)
access_token = creds.token
headers = {âAuthorizationâ: fâBearer {access_token}', âContent-Typeâ: âapplication/jsonâ}
payload = {
âtrigger_idâ: âapi_trigger/trigger_idâ,
âinputParametersâ: {
âparty_nameâ: {âstringValueâ: str(party_id)}
}
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
I obtained the client_id and client_secret from the OAuth 2.0 client IDs section of Credentials page. I obtained the refresh token from the Oauth 2.0 playground by authorizing the APIs and exchanging the authorization code for tokens. I am able to see the response in the OAuth Playground when I post a request there as the Authenticatio_token gets added there automatically. I am facing the issue when I am trying to get the acccess_token from my Flask Application. I am seeing the access_token as 'None" even though the client_id, client_secret and refresh_token are set correctly. It would be great if anyone can help me to solve this issue.