CEDAR

CEDAR

CEDAR

Home page CEDAR


CEDAR APIs


CEDAR API and Python

Prerequisites:

  1. Create file called: secret.py
    1. Add the following line of code: CedarApiKey = 'apiKey key'
      1. Where key is a long hexastring. Literally after '=' it should read: 'apiKey 3453a54f345c345345'.
      2. You can find your CEDAR API key by logging in to your CEDAR account, then navigating to your profile page. Your API key, and basic information about using it, should be visible on this page.
  1. Add External Access rule and turn the rule on
    1. Rule name
      IP Address
      Port
      Reason
      Cedar
      171.67.213.63
      443
      Accessing Cedar


Python code

See also attachment below
  1. import json
  2. import secret

  3. # Open the Cedar template in your browser, paste the url between the triple quotes in its completeness
  4. # This script will extract the template-instance id (URL is non working example)
  5. template_instance_url = '''
  6. https://cedar.metadatacenter.org/instances/edit/https://repo.metadatacenter.org/template-instances/74eb7227-205d-48bd-b200-c79f356ac470?folderId=https:%2F%2Frepo.metadatacenter.org%2Ffolders%2F61f487eb-a59a-4ac8-bc28-21b38cb81ebb
  7. '''

  8. # Getting the Cedar Secret key from secert.py
  9. CedarApiKey = secret.CedarApiKey

  10. # needed to codify the url needed for Cedar get and put
  11. def codify_url(uri):
  12.     return uri.replace('/', '%2F').replace(':', '%3A')


  13. # getting the Template Instance

  14. ## extract the template_instance id
  15. find_string = 'template-instances/'
  16. pos = template_instance_url.find(find_string) + len(find_string)
  17. template_instance = template_instance_url[pos:pos+36]

  18. ## reconstructing the URL needed for get
  19. base_url = 'https://resource.metadatacenter.org/template-instances/'
  20. url = codify_url('https://repo.metadatacenter.org/template-instances/')
  21. url = base_url + url + template_instance
  22. # print(url)

  23. headers = {'Content-Type': 'application/json', 'Authorization': CedarApiKey}

  24. ## geting the Cedar template
  25. req = requests.get(url, headers=headers) #, files=files)
  26. template = json.loads(req.content)
  27. for item in template.items:
  28.     print(item)

  29. ### do your stuff with template ###
  30. # examine the above structure to assign new values
  31. # e.g. template['Date']['@value'] = date_string #'2021-05-27'

  32. ## writing to Cedar
  33. headers = {'Content-Type': 'application/json', 'Authorization': CedarApiKey, 'Accept': 'application/json'}
  34. response = requests.put(url, data=json.dumps(template), headers=headers)

  35. if str(response) == '<Response [200]>':
  36.     print('Cedar is successfully updated')
  37. else:
  38.     print('Houston we had a problem updating Cedar, errorcode: ' + str(response))




    • Related Articles

    • Using Castor in Python

      Introduction anDREa would like to thank Reinier van Linschoten for bringing this package and description to our attention. This is a Python package for interacting with the API of Castor Electronic Data Capture (EDC). The package contains functions ...
    • Python, Anaconda and JupyterLab

      With domain allowlisting now being a self-service feature, this is the preferred option. For proxy settings in Anaconda in combination with domain allowlisting, please follow this article: ...
    • CBS OpenData

      CBS OpenData & Python & R / RStudio Update: 2024-02-19 Domain to allow list beta-odata4.cbs.nl Instructions how to use the API https://github.com/statistiekcbs/CBS-Open-Data-v4/tree/master basic.py tested working
    • Domains to be whitelisted/allowlisted for known applications

      First version: 2022-11-01 Last updated: 2024-06-07 Last change: Added link to information on extra settings necessary for Stata. Introduction This is a community effort, if you experience issues, see mistakes/updates, or have other applications that ...
    • Installing PyCharm with Sourcery plugin

      First version: 2023-11-27 Last version: - Last change: - This is a community effort. The article was created by the anDREa Support Team in their spare time. If you have found a more efficient way to approach this, please contact us and we will update ...