xplane-web-api 0.1.0

Bindings to the X-Plane Web APIs (REST and websocket)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
openapi: 3.0.3
info:
  title: X-Plane Local Web API
  version: "3.0"
  description: |
    OpenAPI model for the documented X-Plane local REST Web API using the latest
    versioned REST paths (`/api/v3/...`) plus the unversioned capabilities endpoint.
servers:
  - url: http://localhost:8086
paths:
  /api/capabilities:
    get:
      tags: [Capabilities]
      operationId: getCapabilities
      summary: Get API capabilities and simulator version.
      description: >
        Returns the supported API versions and the running X-Plane version.
        This endpoint is intentionally unversioned (`/api/capabilities`).
      responses:
        "200":
          description: Capabilities payload.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CapabilitiesResponse"
        "403":
          description: Incoming traffic disabled.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"

  /api/v3/datarefs:
    get:
      tags: [Datarefs]
      operationId: listDatarefs
      summary: List datarefs.
      description: >
        Returns datarefs currently registered in the running simulator,
        including built-in and third-party datarefs.
      parameters:
        - name: filter[name]
          in: query
          description: >
            Repeatable exact-match filter by dataref name.
          required: false
          schema:
            type: array
            items:
              type: string
          style: form
          explode: true
        - name: start
          in: query
          description: >
            Inclusive start index for pagination.
          required: false
          schema:
            type: integer
            format: int64
            minimum: 0
        - name: limit
          in: query
          description: >
            Maximum number of records to return for pagination.
          required: false
          schema:
            type: integer
            format: int64
            minimum: 1
        - name: fields
          in: query
          description: >
            Comma-separated field names to return for each record, or `all`
            (default).
          required: false
          schema:
            type: string
      responses:
        "200":
          description: List of datarefs.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/DatarefListResponse"
        "400":
          description: Invalid request.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"
        "403":
          description: Incoming traffic disabled.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"
        "404":
          description: Invalid dataref name filter.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"

  /api/v3/datarefs/count:
    get:
      tags: [Datarefs]
      operationId: getDatarefCount
      summary: Get dataref count.
      description: >
        Returns the current number of registered datarefs in the running
        simulator.
      responses:
        "200":
          description: Count payload.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CountResponse"

  /api/v3/datarefs/{id}/value:
    get:
      tags: [Datarefs]
      operationId: getDatarefValue
      summary: Get a dataref value.
      description: >
        Returns the current value of a dataref, or a single element when an
        array index is provided.
      parameters:
        - name: id
          in: path
          description: Dataref session ID.
          required: true
          schema:
            type: integer
            format: int64
        - name: index
          in: query
          description: Optional array index to read from array datarefs.
          required: false
          schema:
            type: integer
            format: int64
            minimum: 0
      responses:
        "200":
          description: Dataref value payload.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/DatarefValueResponse"
        "400":
          description: Invalid request.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"
        "403":
          description: Incoming traffic disabled.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"
        "404":
          description: Invalid dataref id.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"
    patch:
      tags: [Datarefs]
      operationId: setDatarefValue
      summary: Set a dataref value.
      description: >
        Sets a dataref value. For array datarefs, callers can update one index
        or provide values for the full array.
      parameters:
        - name: id
          in: path
          description: Dataref session ID.
          required: true
          schema:
            type: integer
            format: int64
        - name: index
          in: query
          description: Optional array index to update on array datarefs.
          required: false
          schema:
            type: integer
            format: int64
            minimum: 0
      requestBody:
        required: true
        description: >
          JSON payload containing `data` as a scalar value, full array value,
          or base64 string for binary datarefs.
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/DatarefValueWriteRequest"
      responses:
        "200":
          description: Value was written.
        "400":
          description: Invalid request/body/value.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"
        "403":
          description: Incoming traffic disabled.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"
        "404":
          description: Invalid dataref id.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"

  /api/v3/commands:
    get:
      tags: [Commands]
      operationId: listCommands
      summary: List commands.
      description: >
        Returns commands currently registered in the running simulator,
        including built-in and third-party commands.
      parameters:
        - name: filter[name]
          in: query
          description: >
            Repeatable exact-match filter by command name.
          required: false
          schema:
            type: array
            items:
              type: string
          style: form
          explode: true
        - name: start
          in: query
          description: >
            Inclusive start index for pagination.
          required: false
          schema:
            type: integer
            format: int64
            minimum: 0
        - name: limit
          in: query
          description: >
            Maximum number of records to return for pagination.
          required: false
          schema:
            type: integer
            format: int64
            minimum: 1
        - name: fields
          in: query
          description: >
            Comma-separated field names to return for each record, or `all`
            (default).
          required: false
          schema:
            type: string
      responses:
        "200":
          description: List of commands.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CommandListResponse"
        "400":
          description: Invalid request.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"
        "403":
          description: Incoming traffic disabled.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"
        "404":
          description: Invalid command name filter.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"

  /api/v3/commands/count:
    get:
      tags: [Commands]
      operationId: getCommandCount
      summary: Get command count.
      description: >
        Returns the current number of registered commands in the running
        simulator.
      responses:
        "200":
          description: Count payload.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CountResponse"

  /api/v3/command/{id}/activate:
    post:
      tags: [Commands]
      operationId: activateCommand
      summary: Activate a command for a fixed duration.
      description: >
        Triggers a command for a fixed duration in seconds.
        A duration of `0` behaves like immediate press-and-release.
      parameters:
        - name: id
          in: path
          description: Command session ID.
          required: true
          schema:
            type: integer
            format: int64
      requestBody:
        required: true
        description: >
          JSON payload containing required `duration` in seconds.
          Maximum allowed duration is 10 seconds.
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ActivateCommandRequest"
      responses:
        "200":
          description: Command activated.
        "400":
          description: Invalid request/body/duration.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"
        "403":
          description: Incoming traffic disabled.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"
        "404":
          description: Invalid command id.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"

  /api/v3/flight:
    post:
      tags: [Flight]
      operationId: startFlight
      summary: Start a new flight.
      description: >
        Starts a new flight using a complete flight initialization payload.
      requestBody:
        required: true
        description: >
          Full flight initialization object compatible with X-Plane's Flight
          Initialization API schema.
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/FlightRequest"
      responses:
        "200":
          description: Flight started.
        "400":
          description: Invalid request/body/values.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"
        "403":
          description: Incoming traffic disabled.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"
    patch:
      tags: [Flight]
      operationId: updateFlight
      summary: Update the current flight.
      description: >
        Updates the active flight using a complete or partial flight
        initialization payload.
      requestBody:
        required: true
        description: >
          Partial or full flight initialization object.
          Start location and aircraft are not changeable during update.
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/FlightRequest"
      responses:
        "200":
          description: Flight updated.
        "400":
          description: Invalid request/body/values.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"
        "403":
          description: Incoming traffic disabled.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ApiError"

components:
  schemas:
    ApiError:
      description: >
        Standard REST API error payload returned on non-2xx responses.
      type: object
      required: [error_code, error_message]
      properties:
        error_code:
          description: Machine-readable error code.
          type: string
        error_message:
          description: Human-readable error message.
          type: string

    CapabilitiesResponse:
      description: Supported API versions and running X-Plane version.
      type: object
      required: [api, x-plane]
      properties:
        api:
          description: API capability information.
          type: object
          required: [versions]
          properties:
            versions:
              description: Supported API versions (for example `v1`, `v2`, `v3`).
              type: array
              items:
                type: string
        x-plane:
          description: Simulator build/version information.
          type: object
          required: [version]
          properties:
            version:
              description: Running X-Plane version string.
              type: string

    Dataref:
      description: Dataref descriptor from the running simulator session.
      type: object
      required: [id, name, value_type]
      properties:
        id:
          description: >
            Session-local numeric identifier used to read, write, and subscribe
            to this dataref during the current simulator run.
          type: integer
          format: int64
        name:
          description: Fully qualified dataref name.
          type: string
        value_type:
          description: >
            Dataref value kind: `float`, `double`, `int`, `int_array`,
            `float_array`, or `data` (binary represented as base64 text).
          type: string
          enum: [float, double, int, int_array, float_array, data]

    Command:
      description: Command descriptor from the running simulator session.
      type: object
      required: [id, name, description]
      properties:
        id:
          description: >
            Session-local numeric identifier used to activate and subscribe to
            this command during the current simulator run.
          type: integer
          format: int64
        name:
          description: Fully qualified command name.
          type: string
        description:
          description: Human-readable command description.
          type: string

    DatarefListResponse:
      description: Response wrapper for dataref list queries.
      type: object
      required: [data]
      properties:
        data:
          description: Array of dataref descriptors.
          type: array
          items:
            $ref: "#/components/schemas/Dataref"

    CommandListResponse:
      description: Response wrapper for command list queries.
      type: object
      required: [data]
      properties:
        data:
          description: Array of command descriptors.
          type: array
          items:
            $ref: "#/components/schemas/Command"

    CountResponse:
      description: Response wrapper for count endpoints.
      type: object
      required: [data]
      properties:
        data:
          description: Count value.
          type: integer
          format: int64

    DatarefValue:
      description: >
        Dataref value represented as JSON. Scalars and arrays map to native JSON
        number/array values; binary `data` values are base64-encoded strings.

    DatarefValueResponse:
      description: Response wrapper for a single dataref value read.
      type: object
      required: [data]
      properties:
        data:
          description: Current dataref value.
          $ref: "#/components/schemas/DatarefValue"

    DatarefValueWriteRequest:
      description: Request payload for writing a dataref value.
      type: object
      required: [data]
      properties:
        data:
          description: Value to write.
          $ref: "#/components/schemas/DatarefValue"

    ActivateCommandRequest:
      description: Request payload for fixed-duration command activation.
      type: object
      required: [duration]
      properties:
        duration:
          description: >
            Command active duration in seconds.
            `0` means immediate press-and-release.
          type: number
          format: double
          minimum: 0
          maximum: 10

    FlightRequest:
      description: >
        Flight initialization payload wrapper used for start/update flight REST
        operations.
      type: object
      required: [data]
      properties:
        data:
          description: >
            Flight initialization object compatible with X-Plane's Flight
            Initialization API.
          type: object
          additionalProperties: true