OK, sorry, it does create the database but still not the property :(

url = "http://127.0.0.1:52773/api/docdb/v1/DEMO/db/Demo.TEST11"


header = {
        'Content-Type': 'application/json',
    }


def getPropertyUrl(property, host = "127.0.0.1", port = 52773,  namespace = "DEMO", db = "DEMO.TEST11"):
    return "http://{}:{}/api/docdb/v1/{}/prop/{}/{}" .format(*[host, port, namespace, db, property])

def main():
    session = requests.Session()
    session.auth = ("_SYSTEM", "SYS")

    response = session.get(url, headers=header)

    print(response.status_code)  # Number of error

    if response.status_code == 404:
        print('DB not found, create DB ...')
        response = session.post(url, headers=header)
        print(response.status_code)
    elif response.status_code != 200:
        print('Unknown error: ' + response.status_code + ' ' + response.reason)
    else:
        property = "Ergebniszuf"
        # check that property exist
        response = session.get(getPropertyUrl(property), headers=header)

        if response.status_code == 404:
            print('Property not found, creating property: ' + property)
            response = session.post(getPropertyUrl(property), params= {"type":"%Numeric", "path": property, "unique":0}, headers=header)
            print(response)
        elif response.status_code != 200:
            print('Unknown error: ' + response.status_code + ' ' + response.reason)
        else:

            print('DB found, load data...')

    return 1


if __name__ == '__main__':
    print(main())

That  is my code now, but the result is still as the screenshot above..
 

Hi Eduard, 

thank you for your answer. 
I do know how to call it, but I don't know where schould I add it. 

Should I add the url in the header or should I create a new header - header2 - and separate it with comma from 

 'Content-Type': 'application/json'

or how can I call it in my code that I shared:

url = "http://127.0.0.1:52773/api/docdb/v1/NamespaceName/db/DBName"
url2 = "http://127.0.0.1:52773/api/docdb/v1/NamespaceName/doc/DBName/"


header = {
        'Content-Type': 'application/json',
    }
    
response = requests.get(url, headers=header)
print(response.status_code)     #Number of error

if response.status_code == 404:
        print('DB not found, create DB ...')
        response = requests.post(url, headers=header)
        print(response.status_code)
else:
        print('DB found, load data...')


Can you please add the following urls in my code at the right place?
 

http://127.0.0.1:52773/api/docdb/v1/NamespaceName/db/DBName/Ergebniszuf?type=%Numeric&path=Ergebniszuf&unique=0
http://127.0.0.1:52773/api/docdb/v1/NamespaceName/db/DBName/Jahr?type=%Integer&path=Jahr&unique=0

Thank you in advance

Hi, thank you for your response @Robert Camper!

set filename = "path/to/file.json" <- here is my path, for example /home/test.json
That was not the problem. I didn't find the problem in my code.

Anyway I have changed my code to:

Class User.MyClass Extends %CSP.REST
{

XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ]
{
<Routes>
<Route Url="/test" Method="GET" Call="getFile" />
</Routes>
}


ClassMethod getFile() as %Status
{
    set filename = "/home/test.json"
    set newArray={}.%FromJSON(filename)
    write "New entity:"_newArray.%ToJSON()
    }

and I become the output, but at the end there is an error:

[" zDispatchRequest+42^%CSP.REST.1 *Function must return a value at zgetFile+4^User.MyClass.1" ] } ], "summary":"ERROR #5002: Cache error: zDispatchRequest+42^%CSP.REST.1 *Function must return a value at zgetFile+4^User.MyClass.1" }

Do you know what does it mean?

I just try some examples from the documentation.

ClassMethod getFile() as %Persistent
{
    set filename = "path/to/file.json"
    set stream = ##class(%Stream.FileCharacter).%New()
    set sc = stream.LinkToFile(filename)    
    set obj = ##class(%DynamicAbstractObject).%FromJSON(stream)
    set jsonObj = [].%FromJSON(filename)
    set i = jsonObj.resultSets.%GetIterator()
    while i.%GetNext(.key , .resultSet ) {
    set i2 = resultSet.rowSet.%GetIterator()
    write resultSet.name,!
    while i2.%GetNext(.key , .rowSet ) {
        write rowSet.%Get(0),!
    }
}

So, row 8 is: set obj = ##class(%DynamicAbstractObject).%FromJSON(stream)