RestApiPost call no response?

I’m running a python-orthanc version (via Docker) and I’m trying to get a study modification script to run.
For this I have an OnChange callback defined in a python file and added this python file to the configuration.

If I do something like:

study_url = ‘/studies/%s’ % (resourceId)
replace = {‘PatientName’ : ‘PROCESS’, ‘StationName’:name, ‘StudyDescription’:name}
request = {‘Replace’:replace, ‘Force’:True}
resp = orthanc.RestApiPost(study_url+‘/modify’,json.dumps(request))

There is no resp object. And nothing seems to work anymore. I must be doing something wrong, but the question is, what? A similar approach using a lua script does work. Any suggestions?


Here is a full working sample:

import json
import orthanc

def OnRest(output, uri, **request):
if request[‘method’] != ‘POST’ :
STUDY = request[‘body’]
replace = { ‘PatientName’ : ‘PROCESS’,
‘StationName’ : ‘STATION’,
‘StudyDescription’ : ‘DESCRIPTION’}
request = { ‘Replace’ : replace }
resp = json.loads(orthanc.RestApiPost(
‘/studies/%s/modify’ % STUDY, json.dumps(request)))

output.AnswerBuffer(‘ID of the modified study: %s\n’ % resp[‘ID’], ‘text/plain’)

orthanc.RegisterRestCallback(‘/test’, OnRest)

Here is how to call this script (the input is the Orthanc ID of one sample DICOM study that is stored in my Orthanc server):

$ curl http://localhost:8042/test -d ‘66c8e41e-ac3a9029-0b85e42a-8195ee0a-92c2e62e’
ID of the modified study: 964e04a0-e055a001-d66673ec-23e16f4f-209dd604

One can check that the modification was correctly applied by opening the following URI (obviously, use the ID of the modified study):

$ curl http://localhost:8042/studies/964e04a0-e055a001-d66673ec-23e16f4f-209dd604/shared-tags


Hi Sébastien,

thank you for your response, I’ll try that, although I’m using the standard api route studies/id/modify.
I thought that orthanc.RestApiPost() was basicly the same as RestApiPost in lua, but apparently not? orthanc.RestAPiGet does get a response and so does orthanc.RestApiDelete (None), that’s a but confusing.

Best, Jaap

Hmm, cant edit, my previous answer.

So why would you build a custom post route (/test), which in its turn queries a second post route (/modify)? I want to directly use the modify route, but it’s not responding, when using orthanc.RestApiPost. When I use an old python script (, it does respond.
When using orthanc.RestApiPost, the dataset is changed, but I don’t get a response telling me that.

Best, Jaap

It’s you who, in the first line of your original question, has talked about the Python plugin (this is the purpose of the “jodogne/othanc-python” Docker images). So, I answer about the Python plugin.

Now, if you want to learn about the “/modify” route, check out the Orthanc Book:

Multiple samples are available in the automated integration tests of Orthanc (look for “/modify”):

If you still cannot make it work, please post a complete, minimal working example:


I thought that the python plugin could be seen as an alternative to lua scripts (I have more experience with python then lua). But apparently I misunderstood, my apologies.

So I’m using the following:

def OnChange(changeType, level, resourceId):
if changeType == orthanc.ChangeType.STABLE_STUDY:
dicom_headers = json.loads(orthanc.RestApiGet(‘/studies/%s/shared-tags?simplify’ % (resourceId)))
metadata = json.loads(orthanc.RestApiGet(‘/studies/%s/metadata?expand’ % (resourceId)))
if ‘ModifiedFrom’ not in metadata:
name = ‘NAME’
study_description = ‘STUDY_DESCRIPTION’
replace = {‘PatientName’ : name,‘StudyDescription’:study_description}
request = {‘Replace’:replace, ‘Force’:True}
url = ‘/studies/%s/modify’ % (resourceId)
resp = json.loads(orthanc.RestApiPost(url,json.dumps(request)))
resp = json.loads(orthanc.RestApiDelete(‘/studies/%s’ % (resourceId)))

I left out some parts, I intend to check a database for names/descriptions, and based on certain rules, change the headers to certain values, but that’s not the issue, so I left it out.
It’s the last 3 lines, where RestApiGet gives a response, the RestApiPost call does not.

In your examples you use the Toolbox (DoPost, etc) and that does work. I’ll use that.