Top Menu

Jump to content
Home
    Modules
      • Projects
      • Activity
      • Work packages
      • Gantt charts
      • Calendars
      • Team planners
      • Boards
      • News
    • Getting started
    • Introduction video
      Welcome to OpenProject Community
      Get a quick overview of project management and team collaboration with OpenProject. You can restart this video from the help menu.

    • Help and support
    • Upgrade to Enterprise edition
    • User guides
    • Videos
    • Shortcuts
    • Community forum
    • Enterprise support

    • Additional resources
    • Data privacy and security policy
    • Digital accessibility (DE)
    • OpenProject website
    • Security alerts / Newsletter
    • OpenProject blog
    • Release notes
    • Report a bug
    • Development roadmap
    • Add and edit translations
    • API documentation
  • Sign in
      Forgot your password?

      or sign in with your existing account

      Google

Side Menu

  • Overview
  • Activity
    Activity
  • Roadmap
  • Work packages
    Work packages
  • Gantt charts
    Gantt charts
  • Boards
    Boards
  • Wiki
    Wiki

Content

Wiki
  1. Stream Nextcloud app "OpenProject Integration"
  2. Wiki
  3. Wiki
  4. curl API Tests
More
  • Print
  • Table of contents

curl API Tests

More
  • Print
  • Table of contents
Export
Export
  • Atom
  • Markdown

The following BASH script contains a number of "curl" calls to the Nextcloud API in order to validate a basic synchronization algorithm.

#!/usr/bin/bash


# OpenProject -> Nextcloud Sync Algorithm:
#
# We represent OpenProject project membership by sharing the project folder
# with the respective users or groups in Nextcloud:
#
# Go through the list of OpenProject Projects:
#	Identify the project folder below the OpenProject root in Nextcloud
#	Create a project folder (using WebDAV Folder API) if it doesn't exist yet
#	Go through the list of OpenProject project members (groups an users from LDAP)
#	and their permissions and compare with Nextcloud shares
#		Create a new Nextcloud share for the user or group if necessary
#		Delete an old NC share if not in OpenProject
#
# Synchroneous operation (as part of the GUI):
#	New project: Sync the new project
#	New project member: Just sync the specific share
#
# Special cases:
#	New group member in LDAP:
#	This could be an issue in the case of a new employee
#	because both systems need to be synced with LDAP.


# Implement getting/setting of "Advanced Permissions" (ACL) via OCS API #1256
# https://github.com/nextcloud/groupfolders/issues/1256
# - Managing

# -------------------------------------------------------
# Run Nextcloud OCC CLI commands

# Taken from nextcloud-link - Node.js interface for Nextcloud including Group Folders
# From: https://github.com/tentwentyfour/nextcloud-link/blob/master/tests/groupfolders-jest.ts
#
# docker exec -u 33 -it integration_openproject_nc bash -c 'php occ list'
# docker exec -u 33 -it integration_openproject_nc bash -c 'php occ app:install groupfolders'


# -------------------------------------------------------
# Get the list of users:
curl -u admin:admin -H "OCS-APIRequest: true" -H 'Accept: application/json' -X GET 'http://localhost/ocs/v1.php/cloud/users'
# {"ocs":{...},"data":{"users":["admin","user1","user2","user3"]}}}

# Get detailed information about one user:
curl -u admin:admin -H "OCS-APIRequest: true" -H 'Accept: application/json' -X GET 'http://localhost/ocs/v1.php/cloud/users/admin'
# {"ocs":{...},"data":{"enabled":true,"storageLocation":"\/var\/www\/html\/data\/admin","id":"admin","email":"admin@example.com","displayname":"admin","groups":["admin"],"language":"en", ...}}}


# -------------------------------------------------------
# Capabilities API:
curl -u admin:admin -X GET  -H "OCS-APIRequest: true" -H 'Accept: application/json' 'http://localhost/ocs/v1.php/cloud/capabilities'
# {"ocs":{"meta":{"status":"ok","statuscode":100,"message":"OK","totalitems":"","itemsperpage":""},"data":{"version":{"major":23,"minor":0,"micro":2,"string":"23.0.2","edition":"","extendedSupport":false}, ...}


# -------------------------------------------------------
# Group Folders API:

# Not working:
# curl -u admin:admin -H "OCS-APIRequest: true" -H 'Accept: application/json' -X GET 'http://localhost/ocs/v2.php/apps/groupfolders/folders'

# Not working:
# curl -u admin:admin -H "OCS-APIRequest: true" -H 'Accept: application/json' -X GET 'http://localhost/ocs/v2.php/apps/groupfolders/folders/1'

# Working:
# curl -u admin:admin -H "OCS-APIRequest: true" -H 'Accept: application/json' -X GET 'http://localhost/ocs/v2.php/apps/activity/api/v2/activity'

# Get the list of group folders (working):
# curl -u admin:admin -H "OCS-APIRequest: true" -H 'Accept: application/json' -X GET 'http://localhost/index.php/apps/groupfolders/folders'
# {"ocs":{"meta":{...},"data":{"1":{"id":1,"mount_point":"My Group Folder","groups":{"Test Group":31,"admin":31},"quota":-3,"size":0,"acl":true,"manage":[{"type":"group","id":"admin","displayname":"admin"}]}}}}

# Get details for one folder (working):
curl -u admin:admin -H "OCS-APIRequest: true" -H 'Accept: application/json' -X GET 'http://localhost/index.php/apps/groupfolders/folders/1'
# {"ocs":{"meta":{...},"data":{"id":1,"mount_point":"My Group Folder","groups":{"Test Group":31,"admin":31},"quota":-3,"size":0,"acl":true}}}

# Not Working (error page):
curl -u admin:admin -H "OCS-APIRequest: true" -H 'Accept: application/json' -H "Content-Type: application/json" \
# -X POST 'http://localhost/index.php/apps/groupfolders/folders' --data-raw '{"mount_point":"My Group Folder 2"}'

# Group Folders set ACL (not working):
curl -u admin:admin -X POST -H "OCS-APIRequest: true" -H 'Accept: application/json' 'http://localhost/index.php/apps/groupfolders/folders/1/acs' --data-raw '{"acl":0}'
curl -u admin:admin -X POST -H "OCS-APIRequest: true" -H 'Accept: application/json' 'http://localhost/index.php/apps/groupfolders/folders/1/acs' --data-raw '{"acl":"0"}'
curl -u admin:admin -X POST -H "OCS-APIRequest: true" -H 'Accept: application/json' 'http://localhost/index.php/apps/groupfolders/folders/1/acs' --data-raw '{"acl":"false"}'
curl -u admin:admin -X POST -H "OCS-APIRequest: true" -H 'Accept: application/json' 'http://localhost/index.php/apps/groupfolders/folders/1/acs' --data-raw '{"acl":false}'

# Check if acs:true still set in folder info
curl -u admin:admin -H "OCS-APIRequest: true" -H 'Accept: application/json' -X GET 'http://localhost/index.php/apps/groupfolders/folders/1'


# -------------------------------------------------------
# WebDAV Protocol for Nextcloud:
# https://docs.nextcloud.com/server/latest/developer_manual/client_apis/WebDAV/basic.html
# Get the list of files for user admin in user's home directory
curl -u admin:admin -X PROPFIND 'http://localhost/remote.php/dav/files/admin/' | xml_pp

# Get the list only for Depth=1
curl -u admin:admin -X PROPFIND -H "Depth: 1" 'http://localhost/remote.php/dav/files/admin/' | xml_pp


# List directory with specific attributes with proper XML namespaces
curl -u admin:admin -X PROPFIND \
-d '<?xml version="1.0"?><d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns" xmlns:nc="http://nextcloud.org/ns"><d:prop><d:getlastmodified />' \
'http://localhost/remote.php/dav/files/admin/' 


# List directory with specific attributes with abbreviated namespaces
curl -u admin:admin -X PROPFIND \
	-d '<d:propfind xmlns:d="DAV:"><d:prop><d:getlastmodified /></d:prop></d:propfind>' \
	'http://localhost/remote.php/dav/files/admin/' | xml_pp 

# Download a file
curl -u admin:admin -X GET 'http://localhost/remote.php/dav/files/admin/Nextcloud.png' --output Nextcloud.png

# Create a new folder
curl -u admin:admin -X MKCOL 'http://localhost/remote.php/dav/files/admin/TestFolder'

# Upload same file with different name
curl -u admin:admin -X PUT 'http://localhost/remote.php/dav/files/admin/TestFolder/Nextcloud2.png' --upload-file Nextcloud.png


# -------------------------------------------------------
# Nextcloud Shares API:

# https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-share-api.html

# Get the list of all shares for a given user:
curl -u admin:admin -H 'Accept: application/json' -H 'OCS-APIRequest: true' http://localhost/ocs/v2.php/apps/files_sharing/api/v1/shares
# {"ocs":{"meta":{"status":"ok","statuscode":200,"message":"OK"},"data":[
# {"id":"2","share_type":0,"uid_owner":"admin","displayname_owner":"admin","permissions":19,"can_edit":true,"can_delete":true,"stime":1646926576,"parent":null,"expiration":null,"token":null,"uid_file_owner":"admin","note":"","label":null,"displayname_file_owner":"admin","path":"\/test.txt","item_type":"file","mimetype":"text\/plain","has_preview":true,"storage_id":"home::admin","storage":2,"item_source":348,"file_source":348,"file_parent":6,"file_target":"\/test-user1.txt","share_with":"user1","share_with_displayname":"User1","share_with_displayname_unique":"user1@example.com","status":{"status":"offline","message":null,"icon":null,"clearAt":null},"mail_send":0,"hide_download":0},
# {"id":"1","share_type":3,"uid_owner":"admin","displayname_owner":"admin","permissions":17,"can_edit":true,"can_delete":true,"stime":1646923228,"parent":null,"expiration":null,"token":"KDSfefYx8cycGoG","uid_file_owner":"admin","note":"","label":"","displayname_file_owner":"admin","path":"\/Photos\/Readme.md","item_type":"file","mimetype":"text\/markdown","has_preview":true,"storage_id":"home::admin","storage":2,"item_source":29,"file_source":29,"file_parent":28,"file_target":"\/Readme.md","share_with":null,"share_with_displayname":"(Shared link)","password":null,"send_password_by_talk":false,"url":"http:\/\/localhost\/s\/KDSfefYx8cycGoG","mail_send":0,"hide_download":0}
# ]}}
Loading...