Skip to content

Instantly share code, notes, and snippets.

@sdumitriu
Last active December 22, 2015 01:58
Show Gist options
  • Save sdumitriu/328650b3e6656401283a to your computer and use it in GitHub Desktop.
Save sdumitriu/328650b3e6656401283a to your computer and use it in GitHub Desktop.
PhenoTips - Using curl with REST to manage users and workgroups
# Creating a user:
curl -u Admin:admin -X PUT -d "parent=XWiki.XWikiUsers" -H "Content-Type: application/x-www-form-urlencoded" http://localhost:8080/rest/wikis/xwiki/spaces/XWiki/pages/jdoe
curl -u Admin:admin -X POST -d 'className=XWiki.XWikiUsers&property#first_name=John&property#last_name=Doe&property#email=jdoe@company.com&property#password=pass1234' -H "Content-Type: application/x-www-form-urlencoded" http://localhost:8080/rest/wikis/xwiki/spaces/XWiki/pages/jdoe/objects
# Deleting a user:
curl -u Admin:admin -X DELETE http://localhost:8080/rest/wikis/xwiki/spaces/XWiki/pages/jdoe
# Creating a workgroup:
curl -u Admin:admin -X PUT -d "parent=Groups.WebHome" -H "Content-Type: application/x-www-form-urlencoded" http://localhost:8080/rest/wikis/xwiki/spaces/Groups/pages/Group1
curl -u Admin:admin -X POST -d 'className=PhenoTips.PhenoTipsGroupClass&property' -H "Content-Type: application/x-www-form-urlencoded" http://localhost:8080/rest/wikis/xwiki/spaces/Groups/pages/Group1/objects
# Adding a member to an existing workgroup:
curl -u Admin:admin -X POST -d 'className=XWiki.XWikiGroups&property#member=XWiki.jdoe' -H "Content-Type: application/x-www-form-urlencoded" http://localhost:8080/rest/wikis/xwiki/spaces/Groups/pages/Group1/objects
# The above snippet will add the same member multiple times; so you must first check if the member exists before adding:
curl -s -u Admin:admin http://localhost:8080/rest/wikis/xwiki/spaces/Groups/pages/Group1/objects | grep -q -E '<headline>(\w+:)?XWiki.jdoe</headline>' || curl -u Admin:admin -X POST -d 'className=XWiki.XWikiGroups&property#member=XWiki.jdoe' -H "Content-Type: application/x-www-form-urlencoded" http://localhost:8080/rest/wikis/xwiki/spaces/Groups/pages/Group1/objects
# Deleting a member from a workgroup:
curl -u Admin:admin -X DELETE http://localhost:8080/rest/wikis/xwiki/spaces/Groups/pages/Group1/objects/XWiki.XWikiGroups/`curl -s -u Admin:admin -X GET -o - http://localhost:8080/rest/wikis/xwiki/spaces/Groups/pages/Group1/objects/XWiki.XWikiGroups | grep '<headline>XWiki.jdoe</headline>' | sed -r -e 's/.*<number>([0-9]+)<\/number><headline>XWiki.jdoe<\/headline>.*/\1/'`
# Deleting a workgroup:
curl -u Admin:admin -X DELETE http://localhost:8080/rest/wikis/xwiki/spaces/Groups/pages/Group1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment