Create Jenkins Docker Cloud Dynamic Agent using Jenkins Rest Api

I am trying to create Jenkins Docker cloud dynamic agent but there is no official rest api mentioned in the document so I am trying with http://jenkins_url/scriptText and passing file as form-data but there is no luck yet. Is there any other API I can try?

I tried curl --user ‘username:password’ --data-urlencode “script=$(< /groovy_test.groovy)” http://jenkins_url/scriptText But I am getting 401 Unauthorized