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 ...
    • 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
    • API Methods in myDRE

      Choosing Between API Key Management for Users in myDRE and Data Upload API (also referred to as Data Landing Zone). In myDRE, there are now two distinct methods for uploading data into workspaces using APIs. While they both allow secure file ...
    • API Key Management for Users in myDRE

      Having control over your API access is crucial for maintaining security and independence. In myDRE, users can now manage their own API keys, enabling them to upload data into workspaces with a single key. This provides greater flexibility and ...
    • Domains to be whitelisted/allowlisted for known applications

      First version: 2022-11-01 Last updated: 2025-06-24 Last change: Corrected links Introduction This is a community effort, if you experience issues, see mistakes/updates, or have other applications that you do know what to allowlist, please send a ...