Skip to content

Instantly share code, notes, and snippets.

@swhume
Created September 25, 2021 01:37
Show Gist options
  • Save swhume/4376bbf061b434682795c370fa79819f to your computer and use it in GitHub Desktop.
Save swhume/4376bbf061b434682795c370fa79819f to your computer and use it in GitHub Desktop.
import requests
import json
USERNAME = "username"
PWD = "password"
URL = "http://68.183.158.128:5000/odm"
# create ItemDef
itemdef = {
"_use": "collection",
"OID": "Test.IT.01",
"Name": "Test Item",
"DataType": "text",
"Length": 200,
"Description": [
{"TranslatedText": {"xml_lang": "en", "_content": "This is a test Item with OID as the id"}}
],
"Question": [
{"TranslatedText": {"xml_lang": "en", "_content": "Who invented liquid soap and why?"}}
],
"CodeListRef": {"CodeListOID": "CL.Test.01"},
"Alias": [
{"Context": "Abbreviation", "Name": "IT"}
]
}
r = requests.post(URL + "/itemdef", data=json.dumps(itemdef), headers={"Content-Type": "application/json"}, auth=(USERNAME, PWD))
object_id = ""
if r.status_code == 201:
object_id = json.loads(r.text).get("_id")
print(f"itemdef successfully inserted with _id {object_id}")
else:
print(f"Error loading itemdef: {r.status_code}.")
print(r.text)
exit(0)
# get the ItemDef just created
r = requests.get(URL + "/itemdef/" + object_id, auth=(USERNAME, PWD))
if r.status_code == 200:
print(r.text)
else:
print(f"unexpected return code getting itemdef: {r.status_code}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment