Created
September 25, 2021 01:37
-
-
Save swhume/4376bbf061b434682795c370fa79819f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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