View Source

{info}User share is the object used to control dashboard sharing with users{info}

h1. Get all user shares in the system

h2. Syntax
User shares in the system can be accessed using http GET method through below url:
{code}http://localhost:8810/rest/user_shares{code}
The response is of mime type _application/xml_ and the content is XML representation of all user shares in the system.

h2. Security
You will need to use http BASIC authentication to login as administrator.

h2. Demo
Below [curl|http://curl.haxx.se/] command demonstrates how to get all user shares:
{code}curl -u admin:admin http://localhost:8810/rest/user_shares{code}

h1. Access user share by id

h2. Syntax
User share can be accessed by id using http GET method through below url:
{code}http://localhost:8810/rest/user_shares/<user_share id>{code}
The response is of mime type _application/xml_ and the content is XML representation of the user share.

h2. Security
You will need to use http BASIC authentication to login as administrator or user owning dashboard of the user share.

h2. Demo
Below [curl|http://curl.haxx.se/] command demonstrates how to get user share of id _1_:
{code}curl -u admin:admin http://localhost:8810/rest/user_shares/1{code}

h1. Access user shares of a particular dashboard

h2. Syntax
User shares of particular dashboard can be accessed using http GET method through below url:
{code}http://localhost:8810/rest/user_shares?dashboard_id=<dashboard id>{code}
The response is of mime type _application/xml_ and the content is XML representation of all user shares of specified dashboard.

h2. Security
You will need to use http BASIC authentication to login as administrator or the user owning queried dashboard.

h2. Demo
Below [curl|http://curl.haxx.se/] command demonstrates how to get user shares of dashboard with id _2_:
{code}curl -u admin:admin http://localhost:8810/rest/user_shares?dashboard_id=2{code}

h1. Access user shares of a particular user

h2. Syntax
User shares of particular user can be accessed using http GET method through below url:
{code}http://localhost:8810/rest/user_shares?user_id=<user id>{code}
The response is of mime type _application/xml_ and the content is XML representation of all user shares of specified user.

h2. Security
You will need to use http BASIC authentication to login as administrator or the user being queried.

h2. Demo
Below [curl|http://curl.haxx.se/] command demonstrates how to get user shares of user with id _1_:
{code}curl -u admin:admin http://localhost:8810/rest/user_shares?user_id=1{code}

h1. Update user share

h2. Syntax
User share can be updated by posting xml representation of the user share to below url:
{code}http://localhost:8810/rest/user_shares{code}
Normally you do not need to create the XML from scratch: you may retrieve XML representation of the user share using http GET method, modify certain parts of the XML and post back to above url.
The response is of mime type _text/plain_ and the content is string representation of the user share id being updated.

h2. Security
You will need to use http BASIC authentication to login as administrator or user owning dashboard of the user share.

h2. Demo
We will use [curl|http://curl.haxx.se/] to demonstrate how to share dashboard _project1_ with _user1_ instead of _user2_:
# Assume id of dashboard _project1_ is _2_, id of user _user1_ is _1_, and id of user _user2_ is _2_. Ids of these entities can be accessed using [id service|retrieve object identifier].
# Run below command to get user shares of dashboard _project1_:
{code}curl -u admin:admin http://localhost:8810/rest/user_shares?dashboard_id=2{code}
# Analyze response of above command to find out the user share with user id _1_. Save xml snippet of found user share to a temp file, say _tempfile.xml_.
# Modify _tempfile.xml_ and change the _user_ element to use value of _2_.
# Post content of _tempfile.xml_ back to QuickBuild using below command:
{code}curl -X POST -u admin:admin -d@tempfile.xml http://localhost:8810/rest/user_shares{code}

h1. Create user share

h2. Syntax
User share can be created by posting XML representation of the user share to below url:
{code}http://localhost:8810/rest/user_shares{code}
A sample user share XML representation is like below:
{code}
<com.pmease.quickbuild.model.UserShare>
<!-- id of associated user of this user share. -->
<user>2</user>

<!-- id of associated dashboard of this user share. -->
<dashboard>1</dashboard>
</com.pmease.quickbuild.model.GroupShare>
{code}
The response is of mime type _text/plain_ and the content is string representation of the newly created user share id.

h2. Security
You will need to use http BASIC authentication to login as administrator or user owning dashboard of the user share.

h2. Demo
We will use [curl|http://curl.haxx.se/] to demonstrate how to share dashboard _project1_ (assume id is _2_) with user _user1_ (assume the id is _3_).
# Save below content into file _tempfile.xml_:
{code}
<com.pmease.quickbuild.model.UserShare>
<dashboard>2</dashboard>
<user>3</user>
</com.pmease.quickbuild.model.UserShare>
{code}
# Post content of _tempfile.xml_ to QuickBuild using below command:
{code}curl -X POST -u admin:admin -d@tempfile.xml http://localhost:8810/rest/user_shares{code}

h1. Delete user share

h2. Syntax
User share can be deleted using http DELETE method through below url:
{code}http://localhost:8810/rest/user_shares/<user share id>{code}
Here _<user share id>_ stands for id of the user share to be deleted.

h2. Security
You will need to use http BASIC authentication to login as administrator or user owning dashboard of the user share.

h2. Demo
Below [curl|http://curl.haxx.se/] command demonstrates how to remove user _user1_ (assume id is _3_) from share list of dashboard _project1_ (assume the id is _2_).
# Get user shares of dashboard _project1_ with below command:
{code}curl -u admin:admin http://localhost:8810/rest/user_shares?dashboard_id=2{code}
# Analyze response of above command to find out id of the user share associated with user id _3_, assume id of the found user share is _100_.
# Delete the found user share with below command:
{code}curl -X DELETE -u admin:admin http://localhost:8810/rest/user_shares/100{code}