Last active
July 21, 2017 19:07
-
-
Save danallison/0dd7449280cae0cb494f081dbd3bd881 to your computer and use it in GitHub Desktop.
10kft API Example. Get users currently assigned to a project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Get users currently assigned to a project\n", | |
"\n", | |
"In this example, we use the assignments and users endpoints to get the users who are currently assigned to a project. In the assignments request, we will use the optional `from` and `to` params to filter the assignments to only those that overlap today's date. Then, we will select the `user_id`s from the assignments and use those ids to get the users from the users endpoint.\n", | |
"\n", | |
"## Endpoints\n", | |
"\n", | |
"```\n", | |
"GET /api/v1/projects/<project_id>/assignments\n", | |
"\n", | |
"GET /api/v1/users\n", | |
"```\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Import libraries\n", | |
"import requests\n", | |
"import datetime\n", | |
"\n", | |
"# Construct the url for the assignments request\n", | |
"base_url = 'https://api.10000ft.com'\n", | |
"project_id = 12345\n", | |
"url = '{0}/api/v1/projects/{1}/assignments'.format(base_url, project_id)\n", | |
"url" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Replace this with your auth token\n", | |
"auth_token = '*** replace with your auth token ***'\n", | |
"\n", | |
"# Today's date in the format \"YYYY-MM-DD\"\n", | |
"today = str(datetime.date.today())\n", | |
"\n", | |
"# In the params, we use the optional \"from\" and \"to\" to\n", | |
"# filter the assignments to only those that overlap today.\n", | |
"params = {\n", | |
" 'auth': auth_token,\n", | |
" 'per_page': 100,\n", | |
" 'from': today,\n", | |
" 'to': today\n", | |
"}\n", | |
"params" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Make the request to get the assignments\n", | |
"response = requests.get(url, params=params)\n", | |
"assignments = response.json()['data']\n", | |
"\n", | |
"# Select the user_ids\n", | |
"user_ids = [a['user_id'] for a in assignments]\n", | |
"user_ids" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"url = '{0}/api/v1/users'.format(base_url)\n", | |
"\n", | |
"params = {\n", | |
" 'auth': auth_token,\n", | |
" 'per_page': 100,\n", | |
" 'id': user_ids\n", | |
"}\n", | |
"\n", | |
"# Make the request to get the users\n", | |
"response = requests.get(url, params=params)\n", | |
"users = response.json()['data']\n", | |
"users" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.1" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment