Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example monday python google cloud function #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions monday/google_cloud/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This lambda_function is a simple / minimal example of how to integrate with the monday.com graphQL API to get back a table of boards.

It can be used by following the fivetran setup guide for google cloud functions. Don't forget to add the accompanying requirements.txt and select a Python 3.x runtime. Python 3.8 was used to create this function.

This is the structure of the data that accompanies this function in the fivetran connections "secrets" field:
{
"apiKey": "your monday.com api key here",
"limit": 1000
}
58 changes: 58 additions & 0 deletions monday/google_cloud/lambda_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import requests
from datetime import datetime,timezone

def get_request(query, apiKey, apiUrl):
headers = {"Authorization" : apiKey}
response = requests.post(url=apiUrl, json={'query' : query}, headers=headers)
if response.status_code == 200:
response = response.json()
return response["data"]
else:
return {}

def build_response(data, limit, cursor_value):
response = dict()

response['insert'] = {"boards": []} # If we had more endpoints we could add them here
# and we would need to add them to the 'insert' section of the response below
for row in data:
response['insert']["boards"].append(row)

response['state'] = {'cursor': cursor_value} if len(data) == 0 else {'cursor': datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S")}
response['schema'] = {"boards": {'primary_key': ["id"]}} # If we had more endpoints, we would need to add the schemas / primary keys here as well
response['hasMore'] = False if len(data) < limit else True
return response

def lambda_handler(request):
# Get json from request
request = request.get_json()
# Note that get_json above is a flask function, which seems to work because google cloud functions are run
# in a flask based environment, even though we didn't import it explicitly or add it to requirements.txt

# Import credentials
# These and other parameters should be wrapped up in 'request,' which is relayed from the connector's 'secrets'
apiKey = request['secrets']['apiKey']

# Set state
try:
cursor_value = request['state']['cursor']
except KeyError:
cursor_value = '1970-01-01T00:00:00'

# Set the 'limit' according to your estimates of the table's size and row count
# Again, these can also be stored in 'request'
limit = request['secrets']['limit']

# Get data
apiUrl = "https://api.monday.com/v2"
boards_query = '{ boards {id name state board_folder_id } }'
boards_data = get_request(boards_query, apiKey=apiKey, apiUrl=apiUrl)

if len(boards_data) == 0:
return {}

response = build_response(boards_data["boards"], limit, cursor_value)

print(response)

return response
3 changes: 3 additions & 0 deletions monday/google_cloud/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Function dependencies, for example:
datetime >= 3.0.0
requests >= 2.0.0