Error when trying to update the watchlist for a group via API (PUT groups/{id}.json)

Priority/Severity:

medium to high

Platform:

Python script as well as cURL command line

Discourse server version:

3.6.0.beta3-latest (6adb4f8e84)

Description:

when trying to update the ‘watching_category_ids’ of an existing group, my python script (using simple “requests.put” reports the following error:

_doPut> ERROR from request:  422 Unprocessable Entity {‘user_count’: 2, ‘errors’: [‘You supplied invalid parameters to the request: update_existing_users’]}

even if there is no parameter called update_existing_users in my json data.

Using cURL to check via:

curl -k -L -X PUT -H 'api-key:xyz’ \
   -H 'api-username:system'  \
   -H 'Accept:application/json;charset=utf-8'  \
   -H 'Content-Type:application/json'   \
   --data '{"group":{"name":"eb-chair-exo","watching_category_ids":[336,337]}}' \
   https://cms-phys-talk.web.cern.ch/groups/46.json

I get the same error:

{“user_count”:2,“errors”:[“You supplied invalid parameters to the request: update_existing_users”]}%

Reproducible steps:

curl -k -L -X PUT -H 'api-key:xyz’ \
   -H 'api-username:system'  \
   -H 'Accept:application/json;charset=utf-8'  \
   -H 'Content-Type:application/json'   \
   --data '{"group":{"name":"eb-chair-exo","watching_category_ids":[336,337]}}' \
   https://cms-phys-talk.web.cern.ch/groups/46.json

edit: added discourse server version

Yeah, that endpoint is a little odd. We wanted to warn staff members about the number of potentially affected users and offer them the ability to choose between applying the change retroactively or not.

That’s why you’re seeing the “{ 'user_count': 2, ... }” in the response from the server.

I’ve clarified the error message so it makes more sense and also improved the front-end code to better handle this “use case” as well as adding specs

Hi - and thanks for the fast action ! :slight_smile:

Unfortunately I’m still confused: I need to set the value for the watching_category_idsfor a given group, and even if the error message now is changed, it’s still a 422 error. So how can I update the group with the new list of watching_category_ids via a script using the rest-API ?

I have already tried to add "update_existing_users”=True in the json data of the PUT call, the error was the same as reported. :frowning:

Thanks again,

cheers, Andreas

It expects the string “true” - lowercase.

Thanks a ton, @zogstrip ! Works now ! :smiley:

(and just for reference, the "update_existing_users”=True has to be outside/parallel to the “group” item in the json sent over (shown here in Python syntax, so True gets translated to the string “true”):

            jsonData={
                "group": {
                    "name": f"{groupName}",
                    "watching_category_ids": newWatchList,
                },
                "update_existing_users": True,
            },