# Lister les Id des instructeurs

Pour lister la liste des instructeurs d'une démarche, vous pouvez passez par l'operation getDemarches, voici un exemple :

```bash
API_TOKEN="" DEMARCHE_NUMBER="" ruby ./list_instructeur.rb
```

{% code title="list\_instructeur.rb" %}

```ruby
require 'net/http'
require 'uri'
require 'json'

ENDPOINT = URI('https://demarche.numerique.gouv.fr/api/v2/graphql')
QUERY_INSTRUCTEURS = "
query getDemarche(
  $demarcheNumber: Int!
  $includeInstructeurs: Boolean = true
) {
  demarche(number: $demarcheNumber) {
    id
    number
    groupeInstructeurs @include(if: $includeInstructeurs) {
      ...GroupeInstructeurFragment
    }
  }
}

fragment GroupeInstructeurFragment on GroupeInstructeur {
  id
  number
  label
  instructeurs @include(if: $includeInstructeurs) {
    id
    email
  }
}
"
### 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)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  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 for page
def list_instructeurs(http)
  # the data of our query
  data = {
    "query" => QUERY_INSTRUCTEURS,
    "operationName" => "getDemarche",
    "variables" => {
      "demarcheNumber": ENV.fetch('DEMARCHE_NUMBER') { raise 'missing env var DEMARCHE_NUMBER' }.to_i,
      "includeInstructeurs": true
    }
  }
  # continue pagination
  req = Net::HTTP::Post.new(ENDPOINT, request_headers)
  req.body = data.to_json

  response = http.request(req)

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

http = open_http_connection

# check if we persisted a cursor so we continue polling
data = list_instructeurs(http)
puts "Info: fetched instructeurs ids: #{data}"
```

{% endcode %}

{% hint style="info" %}
L'id de l'instructeur est a utilisé la ou il est demandé, exemple, sur une mutation comme `dossierEnvoyerMessage`
{% 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/lister-les-id-des-instructeurs.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.
