Programatically setting Project topics issue fails


I’m trying to programatically set topics with the API, but I do not know how to format the array for Gitlab to understand my request.

curl --request PUT --header "PRIVATE-TOKEN: TOKEN" \
     --url '' \
     -d "topics=Marked for archival,Missing info"

It seems I need to convert the array I’m receiving from the API into this weird comma separated string, but this is far from intuitive or ideal since it means I need to make changes to the data that I initially received from the API in the first place (the data is properly json formatted as a string). What other options do I have here? I would prefer sending over a json formatted array to not mess up any topics that are already set.

Any ideas?

I received a message from the support team. I’m putting this here in case anyone ever has the same question:

As per REST API documentation you can use both query string and json types of the payload.

You need to signal API that the payload data will be provided in json format. With curl you can do that as -H "Content-Type: application/json" header.

If you check Project API documentation there is the topics attribute which is expected to be an array and can be passed as an optional attribute.

So coming back to your question you can try the following example

curl --include -H "PRIVATE-TOKEN: <TOKEN>" -H "Content-Type: application/json" -d '{"topics": ["python", "csv"]}' -X PUT https://<GITLAB_INSTANCE>/api/v4/projects/<PROJECT_ID>