qfieldcloud icon indicating copy to clipboard operation
qfieldcloud copied to clipboard

Adding collaborator to project via QFieldcloud REST API

Open chleeb opened this issue 2 years ago • 1 comments
trafficstars

As this might be a bug or at least a mistake in the documantation, I created an issue out of the discussion.

Best, Christoph

Discussed in https://github.com/opengisch/QField/discussions/3931

Originally posted by chleeb February 20, 2023 Hi,

I wanted to use the QFieldcloud REST API to add an collaborator to an existing QField project in the QField cloud.

Following the documentation (https://docs.qfield.org/reference/qfieldcloud/api/) a data package

{
  "role": "string"
}

is submitted as POST request via api/v1/collaborators/{projectid}/.

However, I wondered if this can be correct as no user name is submitted together with the role.

I tried to implement the POST request into a python script:

response_login = requests.request(
               method = "POST",
               url = "https://app.qfield.cloud/api/v1/auth/login/",
               data = {'username': 'USERNAME', 'password': 'PASSWORD'} )
payload = response_login.json()

response_add_collaborator = requests.request(
               method = "POST",
               url = "https://app.qfield.cloud/api/v1/collaborators/PROJECT_ID/",
               headers = {'Authorization': 'token ' + payload["token"], 'User-Agent': 'sdk|py|0.6.1 python-requests|2.28.2'},
               data = {"role": "editor"})

print(response_add_collaborator)
print(response_add_collaborator.json())

what results in

<Response [500]> {'code': 'unknown_error', 'message': 'QFieldcloud Unknown Error'}

I then played around and added a collaborator in the data package:

data = {"collaborator": "USER", "role": "editor"})

and got:

<Response [400]> {'code': 'validation_error', 'message': 'Validation error'}

Has anyone an idea how to add a collaborator to a project via the API?

Thanks, Christoph

chleeb avatar Mar 04 '23 07:03 chleeb

Hey, @chleeb . Thanks for the report. We do not use this API endpoint on QField, QFieldSync and qfield.cloud anymore, which might explain why we never caught it was broken. Just not to give you false expectations, it will not be in our priority bugfix queue for the upcoming months. Actually we were considering internally to deprecate it. If you rely on this functionality, I am open to keep it, but feel free to send us an email on [email protected] or open a PR fixing it.

suricactus avatar Mar 04 '23 12:03 suricactus