# Changer le groupe instructeur d'un dossier

Lorsqu'une démarche comporte plusieurs groupes d'instructeurs, il peut être nécessaire de réaffecter un dossier d'un groupe à un autre. Cette mutation permet de changer le groupe instructeur responsable du traitement d'un dossier.

{% hint style="info" %}
Pour récupérer la liste des groupes instructeurs d'une démarche et leurs identifiants, consultez la documentation [Lister les Id des instructeurs](/api-graphql/cas-dusages-exemple-dimplementation/lister-les-id-des-instructeurs.md).
{% endhint %}

Vous pouvez tester en executant le script suivant avec les variables d'environnement adaptées :

<pre class="language-bash"><code class="lang-bash"><strong>API_TOKEN="votre_token" DOSSIER_ID="l_id_du_dossier" GROUPE_INSTRUCTEUR_ID="l_id_du_groupe_instructeur" ruby changeGroupeInstructeur.rb
</strong></code></pre>

{% code title="changeGroupeInstructeur.rb" %}

```ruby
# frozen_string_literal: true

require 'net/http'
require 'uri'
require 'json'
ENDPOINT = URI('https://demarche.numerique.gouv.fr/api/v2/graphql')

### that's the GraphQL part.
QUERY = <<~GRAPHQL_QUERY
  mutation dossierChangerGroupeInstructeur($input: DossierChangerGroupeInstructeurInput!) {
    dossierChangerGroupeInstructeur (input: $input) {
      dossier {
        id
        groupeInstructeur {
          id
          label
        }
      }
      errors {
        message
      }
    }
  }
GRAPHQL_QUERY

### that's the HTTP part
# open an http connexion to our GraphQL endpoint
def open_http_connection
  http = Net::HTTP.new(ENDPOINT.host, ENDPOINT.port)
  if ENDPOINT.scheme == 'https'
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
  http
end

# the headers of our http query, include auth
def request_headers
  {
    "Content-Type" => "application/json",
    "Authorization" => "Bearer #{ENV.fetch('API_TOKEN') { raise 'missing env var API_TOKEN' }}"
  }
end

# given an http connexion, request the API
def request_dossier_changer_groupe_instructeur(http)
  # the data of our query
  data = {
    "query" => QUERY,
    "operationName" => "dossierChangerGroupeInstructeur",
    "variables" => {
      "input": {
        dossierId: ENV.fetch('DOSSIER_ID') { raise 'missing env var DOSSIER_ID' },
        groupeInstructeurId: ENV.fetch('GROUPE_INSTRUCTEUR_ID') { raise 'missing env var GROUPE_INSTRUCTEUR_ID' }
      }
    }
  }

  # the HTTP format
  req = Net::HTTP::Post.new(ENDPOINT, request_headers)
  # the request body format
  req.body = data.to_json

  response = http.request(req)

  data = JSON.parse(response.body)
  data
end

http = open_http_connection
data = request_dossier_changer_groupe_instructeur(http)

puts "Info: dossier reassigned to groupe instructeur: #{data}"

```

{% endcode %}

{% hint style="info" %}
La mutation retourne le dossier avec son nouveau groupe instructeur. Vous pouvez voir la documentation complète de cette mutation ici : <https://demarche.numerique.gouv.fr/graphql/schema/mutations/groupeInstructeurModifier>
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.demarches-simplifiees.fr/api-graphql/cas-dusages-exemple-dimplementation/changer-le-groupe-instructeur-dun-dossier.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
