# Rest API

> Flexter offers an option to run commands through Rest API. This option comes with Flexter-UI module and is disabled by default.

---

Site [llms.txt](/flexter/v2.8/llms.txt)

---

## Enabling it

The change must be done at `/usr/share/flexter/flexter-ui/conf/backend.properties` or `~/.local/share/flexter/flexter-ui/conf/backend.properties` for non root installations.

Please set the `cmd.enabled` value as below:

```properties
cmd.enabled = true
```

And after that, please restart the `flexterui-backend` service:

```shell
systemctl restart flexterui-backend
```

## Example job command:

Here is an example of generating a schema from XML. Note that `jq` is used at the end to format the output.

```shell
curl -H 'Content-Type: application/json' -XPOST -d '{
   "executions":[
      {
         "app_name":"xml2er",
         "source":{
            "file":{
               "command":"/usr/share/flexter/samples/donut.xml.gz",
               "enabled":true
            }
         },
         "target":{
            "generation":[
               {
                  "command":"-g",
                  "enabled":"true",
                  "value":"3"
               }
            ]
         }
      }
   ]
}' http://<FLEXTER_UI_SERVER>:<PORT>/v2/run/cmd | jq
```

And the related output:

```json
{
  "error": false,
  "logPath": null,
  "cmds": [
    "xml2er -j 7"
  ],
  "jobs": [
    7
  ]
}
```

## Tracking the job status

You can also track status of the job calling:

```shell
curl http://<FLEXTER_UI_SERVER>:<PORT>/v2/executions/get/7
```

or
```shell
curl http://<FLEXTER_UI_SERVER>:<PORT>/v2/executions/get/7 | jq
```

And get as output:

```json
{
  "params": "/usr/share/flexter/samples/donut.xml.gz -g 3",
  "status": "C",
  "host": "<HOSTNAME>/<IP_ADDRESS>",
  "parm_path_input": null,
  "id_org": 1,
  "base_path": "/",
  "id_app": "local-1674054248306",
  "id_lschma": 4,
  "start_date": 1674054245996,
  "os_user": "root",
  "id_sch": 11,
  "job_type": "Parse",
  "parm_path_output": null,
  "params_json": "{\"spark\": {\"master\": \"local[*]\"}, \"action\": {\"parsemode\": \"s\"}}",
  "msg_proc_qty": 0,
  "log_file": null,
  "id_parent_job": null,
  "end_date": 1674054257301,
  "id_job": 7
}
```

## Example of a more complex job command 

```shell
curl -H 'Content-Type: application/json' -XPOST -d '{
   "executions":[
      {
         "app_name":"xml2er",
         "source":{
            "file":{
               "command":"/usr/share/flexter/samples/donut.xml.gz",
               "enabled":true
            },
            "origin_id":{
               "command":"-x",
               "enabled":true,
               "value":"11"
            }
         },
         "target":{
            "path":{
               "command":"-o",
               "enabled":true,
               "value":"snowflake://<SNOWFLAKE_ADDRESS>?db=<DB>&schema=<SCHEMA>&warehouse=<WAREHOUSE>"
            },
            "format":[
               {
                  "command":"-u",
                  "enabled":"true",
                  "value":"<USER>"
               },
               {
                  "command":"-p",
                  "enabled":"true",
                  "value":"<PASSWORD>"
               }
            ],
            "writing_mode":[
               {
                  "command":"-S",
                  "enabled":"true",
                  "value":"o"
               },
               {
                  "command":"-e",
                  "enabled":"true",
                  "value":"D"
               }
            ]
         }
      }
   ]
}' http://<FLEXTER_UI_SERVER>:<PORT>/v2/run/cmd | jq
```

## Reference files

The [API Reference](https://docs.sonra.io/flexter/v2.8/docs/rest-api/reference/) renders the OpenAPI definition below as an interactive page.

* [Flexter Open API 3 reference](flexter-backend-openapi3.json)
* [Flexter runJob full example](flexter-runJob-full-example.json)

---

Section pages:

- [API Reference](/flexter/v2.8/docs/rest-api/reference/): Interactive reference of the Flexter UI backend API, generated from its OpenAPI 3 definition.
