Back to Gitlabhq

API des attributs personnalisés

doc-locale/fr-fr/api/custom_attributes.md

19.3.03.3 KB
Original Source

{{< details >}}

  • Édition : Gratuite, GitLab Premium, GitLab Ultimate
  • Offre : GitLab Self-Managed, GitLab Dedicated

{{< /details >}}

Utilisez cette API pour gérer les attributs personnalisés des utilisateurs, des groupes et des projets.

Prérequis :

  • Vous devez être administrateur de l'instance.

Lister tous les attributs personnalisés {#list-all-custom-attributes}

Liste tous les attributs personnalisés pour une ressource spécifiée.

plaintext
GET /users/:id/custom_attributes
GET /groups/:id/custom_attributes
GET /projects/:id/custom_attributes
AttributTypeObligatoireDescription
idintegerouiL'identifiant d'une ressource
shell
curl --request GET \
   --header "PRIVATE-TOKEN: <your_access_token>" \
   --url "https://gitlab.example.com/api/v4/users/42/custom_attributes"

Exemple de réponse :

json
[
   {
      "key": "location",
      "value": "Antarctica"
   },
   {
      "key": "role",
      "value": "Developer"
   }
]

Récupérer un attribut personnalisé {#retrieve-a-custom-attribute}

Récupère un attribut personnalisé spécifié pour une ressource.

plaintext
GET /users/:id/custom_attributes/:key
GET /groups/:id/custom_attributes/:key
GET /projects/:id/custom_attributes/:key
AttributTypeObligatoireDescription
idintegerouiL'identifiant d'une ressource
keystringouiLa clé de l'attribut personnalisé
shell
curl --request GET \
   --header "PRIVATE-TOKEN: <your_access_token>" \
   --url "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"

Exemple de réponse :

json
{
   "key": "location",
   "value": "Antarctica"
}

Mettre à jour un attribut personnalisé {#update-a-custom-attribute}

Met à jour ou crée un attribut personnalisé pour une ressource spécifiée. L'attribut est mis à jour s'il existe déjà, ou nouvellement créé dans le cas contraire.

plaintext
PUT /users/:id/custom_attributes/:key
PUT /groups/:id/custom_attributes/:key
PUT /projects/:id/custom_attributes/:key
AttributTypeObligatoireDescription
idintegerouiL'identifiant d'une ressource
keystringouiLa clé de l'attribut personnalisé
valuestringouiLa valeur de l'attribut personnalisé
shell
curl --request PUT \
   --header "PRIVATE-TOKEN: <your_access_token>" \
   --data "value=Greenland" \
   --url "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"

Exemple de réponse :

json
{
   "key": "location",
   "value": "Greenland"
}

Supprimer un attribut personnalisé {#delete-custom-attribute}

Supprime un attribut personnalisé spécifié pour une ressource.

plaintext
DELETE /users/:id/custom_attributes/:key
DELETE /groups/:id/custom_attributes/:key
DELETE /projects/:id/custom_attributes/:key
AttributTypeObligatoireDescription
idintegerouiL'identifiant d'une ressource
keystringouiLa clé de l'attribut personnalisé
shell
curl --request DELETE \
   --header "PRIVATE-TOKEN: <your_access_token>" \
   --url "https://gitlab.example.com/api/v4/users/42/custom_attributes/location"