Adding collaborator to project via QFieldcloud REST API

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 (REST API - QField Ecosystem Documentation) 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


Imported from GitHub discussion by @chleeb on 2023-02-20T20:42:11Z