enter code here
I found the solution!
you have to first convert that groovy script to a JSON file and pass that JSON file to your curl or API(for creating script) that you are working with and we can do it with this python file:
import json
with open("[THE GROOVY FILE]", "r") as inputfile:
filedata = inputfile.read()
jsondata = {}
jsondata['name'] = 'testscript2'
jsondata['type'] = 'groovy'
jsondata['content'] = filedata
with open("[OUTPUT FILE]", "w") as outputfile:
outputfile.write(json.dumps(jsondata))
the output file is something like this:
{
"name": "name",
"type": "groovy",
"content": "..."
}
then use this output file which is a JSON file and pass this to that command and there you go!
the command for creat script with REST API is:
curl -v -X POST -u admin:admin --header "Content-Type: application/json" "http://<url>/service/rest/v1/script" -d @{output}.json
the above command will create a script and you can execute it with:
curl -v -X POST -u admin:admin --header "Content-Type: application/json" "http://<url>/service/rest/v1/script/{name}/run