1

My Url is Like:

https://<ip:port>/TestRESTServices/objects/test-folder

JSON data that I want to pass is:

{
   "name":"test-1",
   "parent-uuid":"126"
}

test-1 is the folder name which i want to create. When i invoke this url with the data in Poster plugin in firefox via POST it works fine and folder test-1 is created.

 //using Content Type : "application/json"

How can I invoke/call this REST API using cURL ? Need Help.

This is what i tried:

 curl -i -H "Accept: application/json" -X POST -d '{"name":"test-1","parent-uuid":"126"}' https://<ip:port>/TestRESTServices/objects/test-folder

It throws an error that curl: (52) Empty reply from server

Vaibhav Jain
  • 3,729
  • 3
  • 25
  • 42

1 Answers1

1

Unfortunately I don't have a REST API online to try it, but resources that I found suggest the following approaches:

curl -v -H "Content-Type: application/json" -X POST --data "@issue.json" -u login:password http://redmine/issues.json

where the issues.json is a file containing the JSON request.

Resources I found useful:

1, 2

Hope it helps!

For Authentication : Give the userid/password as admin:password

  TOKEN=$(curl -s -k -X POST --basic -u "admin:password" "{host}/TestAuthServices/auth/tokens" | sed -rn 's/\{"Token":"([^"]+)".+/\1/p')

After getting this token call curl as:

 curl -s -k -X POST -H "Content-Type: application/json" -H "Authorization: X-SAML ${TOKEN}" -d '{"name":"test","parent-uuid":"126"}' "{host}/TestRESTServices/objects/test-folder"
Community
  • 1
  • 1
Olimpiu POP
  • 5,001
  • 4
  • 34
  • 49
  • SAML_AUTH_TOKEN is required for this for Authentification.Do you have any idea ? – Vaibhav Jain Jan 08 '14 at 09:36
  • I suppose your service requires authentication. I don't know how SAML works but I suppose first you have to make an authentication call, that returns a valid token that will be used afterwards in each call that you make as a header. – Olimpiu POP Jan 08 '14 at 10:32
  • Yes. Solved. I am creating a TOKEN with the userid/password and using that token for the authorization purpose. – Vaibhav Jain Jan 08 '14 at 11:56
  • @VaibhavJain great. Thank you for the edit also, I suggest you edit your question as well to ask also about SAML authentication. Probably title can be edited also. – Olimpiu POP Jan 08 '14 at 12:55
  • @Vibhav How are you generating SAML token with your credentials – Jafar Ali Jan 31 '18 at 15:15