Home page CEDAR


CEDAR API and Python


  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
      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, Miniconda, Jupyterlab & Python Packages

      Basic install Open Ports Anaconda In mydre.org, in tab: external access, add the following rules: Rule & Description IP-address Port conda.anaconda.org 443 repo.anaconda.com 443 docs.conda.io 443 ports might ...
    • CBS OpenData

      Access To access CBS OpenData from within your Workspace: Add External rule Rule name IP-address Port Remark opendata.cbs.nl 443 opendata.cbs.nl Turn on the rule Python & CBS OpenData Download cbsodata....whl from ...
    • 2021-W40 update from anDREa

      anDREa BV and ISO 27001 In many of the documents that can be found in the Knowledge Base or via ISO 27001 - Overview you will read: anDREa is committed to protecting the security of its business information in the face of incidents and unwanted ...
    • Blob storage

      This service is available to Accountables and owners of a workspace. What is Azure Blob storage? Azure Blob storage is optimized for storing massive amounts of unstructured data. Unstructured data is data that does not adhere to a particular data ...