CMDBuild Forum

Sample REST Usage

Hi,

I am exploring the REST Interface for integration / automation purposes. Until now I was able to test th IF with curl -X POST with username and password to the session endpoint. I receive the session ID back, but how would I now go on to get e.g. all the available classes. Or any other information? I always get back a 401 when sending a curl -X GET -d '{"CMDBuild-Authorization":"<someID>"}'

Thanks and regards

Did you check the "Webservice Manual"
 
http://www.cmdbuild.org/file/manuali/webservice-manual-in-english
 
at paragraph "Access to all resources that requires a session" at page 25?
 
It seems that you are not sending the token within headers as specified.
 
Best regards.
 
-- CMDBuild Team
 
Previously Hannes Lehmann wrote:

Hi,

I am exploring the REST Interface for integration / automation purposes. Until now I was able to test th IF with curl -X POST with username and password to the session endpoint. I receive the session ID back, but how would I now go on to get e.g. all the available classes. Or any other information? I always get back a 401 when sending a curl -X GET -d '{"CMDBuild-Authorization":"<someID>"}'

Thanks and regards

 

Hello,

 

indeed I was trying to follow the instructions of that manual. It says "various headers", which are needed? As I mentioned I added a field to the request:

CMDBuild-Authorization":"<someID>"

with <someID> being the ID I receive back when creating a session (page 23). Could you pls give me a working example request which should work, which I can take for further exploration?

 

Thanks and regards

 

 

Previously Tecnoteca wrote:
Did you check the "Webservice Manual"
 
 
at paragraph "Access to all resources that requires a session" at page 25?
 
It seems that you are not sending the token within headers as specified.
 
Best regards.
 
-- CMDBuild Team
 
Previously Hannes Lehmann wrote:

Hi,

I am exploring the REST Interface for integration / automation purposes. Until now I was able to test th IF with curl -X POST with username and password to the session endpoint. I receive the session ID back, but how would I now go on to get e.g. all the available classes. Or any other information? I always get back a 401 when sending a curl -X GET -d '{"CMDBuild-Authorization":"<someID>"}'

Thanks and regards

 

 

A working example:
 
curl -X POST 'http://localhost:8080/cmdbuild/services/rest/v2/sessions' -H "Content-Type: application/json" --data-binary '{"username": "admin", "password": "admin"}'
{
   "data" : {
      "username" : "admin",
      "_id" : "3a44ni7d7fm1mg46okomb6donp",
      "availableRoles" : [
         "Helpdesk",
         "ChangeManager",
         "SuperUser",
         "Specialist"
      ]
   }
}
 
curl -X GET 'http://localhost:8080/cmdbuild/services/rest/v2/classes' -H "Content-Type: application/json" -H "CMDBuild-Authorization: 3a44ni7d7fm1mg46okomb6donp"
{
   "meta" : {
      "total" : 3,
      "references" : {},
      "positions" : {}
   },
   "data" : [
      {
         "parent" : null,
         "name" : "Class",
         "_id" : "Class",
         "prototype" : true,
         "description" : "Class"
      },
      {
         "name" : "Role",
         "parent" : "Class",
         "_id" : "Role",
         "description" : "Groups",
         "prototype" : false
      },
      {
         "name" : "User",
         "parent" : "Class",
         "_id" : "User",
         "prototype" : false,
         "description" : "Users"
      }
   ]
}
 
Best regards.
 
-- CMDBuild Team
 
Previously Hannes Lehmann wrote:

Hello,

 

indeed I was trying to follow the instructions of that manual. It says "various headers", which are needed? As I mentioned I added a field to the request:

CMDBuild-Authorization":"<someID>"

with <someID> being the ID I receive back when creating a session (page 23). Could you pls give me a working example request which should work, which I can take for further exploration?

 

Thanks and regards

 

 

Previously Tecnoteca wrote:
Did you check the "Webservice Manual"
 
 
at paragraph "Access to all resources that requires a session" at page 25?
 
It seems that you are not sending the token within headers as specified.
 
Best regards.
 
-- CMDBuild Team
 
Previously Hannes Lehmann wrote:

Hi,

I am exploring the REST Interface for integration / automation purposes. Until now I was able to test th IF with curl -X POST with username and password to the session endpoint. I receive the session ID back, but how would I now go on to get e.g. all the available classes. Or any other information? I always get back a 401 when sending a curl -X GET -d '{"CMDBuild-Authorization":"<someID>"}'

Thanks and regards

 

 

 

Thank you very much! That helped - indeed I had a wrong curl flag :(

 

Maybe it would be an idea to have some examples somewhere in the manual?

 

Thanks again and regards,

Hannes

 

 

 

Previously Tecnoteca wrote:
A working example:
 
curl -X POST 'http://localhost:8080/cmdbuild/services/rest/v2/sessions' -H "Content-Type: application/json" --data-binary '{"username": "admin", "password": "admin"}'
{
   "data" : {
      "username" : "admin",
      "_id" : "3a44ni7d7fm1mg46okomb6donp",
      "availableRoles" : [
         "Helpdesk",
         "ChangeManager",
         "SuperUser",
         "Specialist"
      ]
   }
}
 
curl -X GET 'http://localhost:8080/cmdbuild/services/rest/v2/classes' -H "Content-Type: application/json" -H "CMDBuild-Authorization: 3a44ni7d7fm1mg46okomb6donp"
{
   "meta" : {
      "total" : 3,
      "references" : {},
      "positions" : {}
   },
   "data" : [
      {
         "parent" : null,
         "name" : "Class",
         "_id" : "Class",
         "prototype" : true,
         "description" : "Class"
      },
      {
         "name" : "Role",
         "parent" : "Class",
         "_id" : "Role",
         "description" : "Groups",
         "prototype" : false
      },
      {
         "name" : "User",
         "parent" : "Class",
         "_id" : "User",
         "prototype" : false,
         "description" : "Users"
      }
   ]
}
 
Best regards.
 
-- CMDBuild Team
 
Previously Hannes Lehmann wrote:

Hello,

 

indeed I was trying to follow the instructions of that manual. It says "various headers", which are needed? As I mentioned I added a field to the request:

CMDBuild-Authorization":"<someID>"

with <someID> being the ID I receive back when creating a session (page 23). Could you pls give me a working example request which should work, which I can take for further exploration?

 

Thanks and regards

 

 

Previously Tecnoteca wrote:
Did you check the "Webservice Manual"
 
 
at paragraph "Access to all resources that requires a session" at page 25?
 
It seems that you are not sending the token within headers as specified.
 
Best regards.
 
-- CMDBuild Team
 
Previously Hannes Lehmann wrote:

Hi,

I am exploring the REST Interface for integration / automation purposes. Until now I was able to test th IF with curl -X POST with username and password to the session endpoint. I receive the session ID back, but how would I now go on to get e.g. all the available classes. Or any other information? I always get back a 401 when sending a curl -X GET -d '{"CMDBuild-Authorization":"<someID>"}'

Thanks and regards