Run script after upload by request

Hello everyone!
Maybe I missed something in docs, hope you will help to find the thing I need.
We have:

  • template file with velocity script
  • brand-new wiki
  • curl request that create new page with content from template file (velocity part as a source, of course).
    The problem is whenever I am uploading content via curl -u Admin:Admin -X PUT --data-binary "@script.xml" -H "Content-Type: application/xml" http://my_ip/rest/wikis/xwiki/spaces/Main/pages/NewPage the script does nothing. Only when I click Edit and than Save – it works.
    I there something I can add to request to make script work once page is created?

WDYM by template file?

So the curl command is working and the page is created?

Are you sure that the Admin user has the proper rights to execute the velocity script? What is the user with which you edit and save?

Sorry for delay in reply.

Saying template I mean something like

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<page xmlns="http://www.xwiki.org">     
<content>
{{velocity}}
#set($reference = $services.model.createDocumentReference('', 'XWiki', 'Test'))
#set($document  = $xwiki.getDocument($reference))
#set($object = $document.getObject('XWiki.XWikiUsers'))
$object.set('email', 'test1@test1.com')
$document.save()
{{/velocity}}
</content>
</page>

Yes, curl is working, the page is created and in it`s content I have the code below. But it works only when I manually click Edit and then Save

I use Admin account both for curl and for manual editing. So yes, it has rights as far as I can see.

UPD I have fount that if after creation of page I run curl -u Admin:Admin http://my_ip/bin/view/Main/NewPage, than script works.

But if you have any idea how to do it in once request – please, let me know.)