I am trying to run an API call in-platform using Google Cloud Functions with this script:
import pandas as pd
import requests
import pandas_gbq
def hello_gcs(data):
## Define table and project id
table_id = 'my_dataset.my_table'
project_id = 'my_project_id'
## API call
url = "https://www.my_api_endpoint.com"
params = {
"apiKey": "ABCD1234"
}
response = requests.get(url, params=params)
api_data = response.json()
sent_data = api_data.get("DATA", {}).get("SENT", [])
## Basic transformation
structured_data = [{
"List_Name": record.get("LISTSENT_NAME"),
"CTR": record.get("CLICKTHROUGH_RATE") ## Add the other fields here (and clean this up)
} for record in sent_data]
df = pd.DataFrame(structured_data)
## Send to BigQuery
pandas_gbq.to_gbq(df, table_id, project_id=project_id, if_exists='replace')
ERROR: failed to build: executing lifecycle. This may be the result of using an untrusted builder: failed with status code: 62
From experimenting, I've figured out that the issue seems to be with the API call.
The API call works when I do it in Python on my desktop, and the script works when I replace the API call with anything else -- but, as far as I can tell, Google just doesn't trust my API for some reason.
What I can do to call the API in a way that makes Google happy?
Solved! Go to Solution.
Hello @takenorinvalid!
Welcome to the Google Cloud Community!
It seems that your problem has already been solved based on this Reddit post that you also posted.
Let me know if you still need help, thanks!
Hello @takenorinvalid!
Welcome to the Google Cloud Community!
It seems that your problem has already been solved based on this Reddit post that you also posted.
Let me know if you still need help, thanks!