From a41554dc4204592be4a227e1c3736fdf30716922 Mon Sep 17 00:00:00 2001 From: smvgarcia <111767892+smvgarcia@users.noreply.github.com> Date: Thu, 12 Dec 2024 11:28:45 -0600 Subject: [PATCH] Update using-api.md change the code so users are not told to paste their API key into their code, but instead reference the file --- .../gen3-resources/user-guide/using-api.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/gen3/docs/gen3-resources/user-guide/using-api.md b/gen3/docs/gen3-resources/user-guide/using-api.md index dcb6a6a6..9537e830 100644 --- a/gen3/docs/gen3-resources/user-guide/using-api.md +++ b/gen3/docs/gen3-resources/user-guide/using-api.md @@ -41,17 +41,20 @@ While displayed, click “copy” to copy the API key to the clipboard or “dow In Python, the following command is sent, using the module “requests”, to receive the access token: ```python -# Save the copied credentials.json from the website and paste the api_key and key_id into a variable "key": -key = { - "api_key": "", - "key_id": "" - } +# Save the credentials.json file from the website. Copy the file path to the credentials file with the key. +# Then, paste the file path as the value for the `key_file` variable -# Import the "requests" Python module: -import requests +import json, requests + +api = "https://yourdatacommons.org" +key_file = "/put_path_to/credentials.json" + +# Read the key from the file and +with open(key_file) as json_file: + key = json.load(json_file) # Pass the API key to the Gen3 API using "requests.post" to receive the access token: -token = requests.post('https://gen3.datacommons.io/user/credentials/cdis/access_token', json=key).json() +token = requests.post('{}/user/credentials/cdis/access_token'.format(api), json=key).json() # Now the access_token should be displayed when the following line is entered: token