Fortinet white logo
Fortinet white logo

New Features

View batch transaction commands through the REST API 7.4.1

View batch transaction commands through the REST API 7.4.1

The commands of an uncommitted batch transaction can be viewed through the REST API from an API client with the transaction-show option. Previously administrators could only view commands of a batch transaction through the CLI.

Example

In this example, use the REST API to change the admin timeout of the FortiGate. Before committing the change, check the cached commands to view the pending changes. After committing the change, you cannot view the commands because the transaction is complete.

To view batch transaction commands with the REST API:
  1. From an API client, start a transaction with FortiGate.

    In this example, the transaction ID is 1.

    user@test:~$ curl -k -X 'POST' 'https://<ip address>/api/v2/cmdb?action=transaction-start&vdom=vdom1&access_token=j8Gcs836dQsqbrd9637Qs770s0f13Q' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -d '{
      "timeout": 60
    }'
    
    response:
    {
      "http_method":"POST",
      "revision":"df4217a73f57e09b766605b683fb5caf",
      "revision_changed":false,
      "results":{
        "transaction-id":1
      },
      "vdom":"vdom1",
      "action":"transaction-start",
      "status":"success",
      "http_status":200,
      "serial":"<serial number>",
      "version":"v7.4.2",
      "build":2484
    
    }
  2. Change the admin timeout on the FortiGate for the started transaction.

    For transaction ID 1, the admintimeout is set to 123.

    user@test:~$ curl -k -X 'PUT' 'https://<ip address>/api/v2/cmdb/system/global?access_token=j8Gcs836dQsqbrd9637Qs770s0f13Q' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -H 'X-TRANSACTION-ID: 1' \
      -d '{
      "admintimeout": 123
    }'
    
    response:
    {
      "http_method":"PUT",
      "revision":"c8263664d73eeff0e47db5e142fa5306",
      "revision_changed":false,
      "status":"success",
      "http_status":200,
      "vdom":"vdom1",
      "path":"system",
      "name":"global",
      "serial":"<serial number>",
      "version":"v7.4.2",
      "build":2484
    }
  3. Before committing the commands, check the cached commands.

    The transaction-show results for transaction ID 1 show the uncommitted changes to admintimeout of 123.

    user@test:~$ curl -k -X 'GET'  'https://<ip address>/api/v2/cmdb?action=transaction-show&transaction-id=1&access_token=j8Gcs836dQsqbrd9637Qs770s0f13Q' \
      -H 'accept: application/json'
    
    response:
    {
      "http_method":"GET",
      "revision":"df4217a73f57e09b766605b683fb5caf",
      "results":[
        " config global",
        "  config system global",
        "      set admintimeout 123",
        "  end",
        " end"
      ],
      "vdom":"vdom1",
      "action":"transaction-show",
      "status":"success",
      "http_status":200,
      "serial":"<serial number>",
      "version":"v7.4.2",
      "build":2484
    
    }
  4. Commit transaction ID 1:

    user@test:~$ curl -k -X 'POST'   'https://<ip address>/api/v2/cmdb?action=transaction-commit&vdom=vdom1?access_token=j8Gcs836dQsqbrd9637Qs770s0f13Q'   -H 'accept: application/json'   -H 'Content-Type: application/json'   -d '{
      "transaction-id": 1
    }'
    
    response:
    {
      "http_method":"POST",
      "revision":"df4217a73f57e09b766605b683fb5caf",
      "revision_changed":false,
      "status":"success",
      "http_status":200,
      "vdom":"vdom1",
      "action":"transaction-commit",
      "serial":"<serial number>",
      "version":"v7.4.2",
      "build":2484
    }
  5. Check the commands for transaction 1. An error is returned as expected because transaction 1 is complete. No cached commands are available to be viewed.

    user@test:~$ curl -k -X GET'   'https://<ip address>/api/v2/cmdb?action=transaction-show&transaction-id=1&access_token=j8Gcs836dQsqbrd9637Qs770s0f13Q'   -H 'accept: application/json'            
    
    response:
    
    {
      "http_method":"GET",
      "revision":"df4217a73f57e09b766605b683fb5caf",
      "error":-651,
      "status":"error",
      "http_status":500,
      "vdom":"vdom1",
      "action":"transaction-show",
      "serial":"<serial number>",
      "version":"v7.4.2",
      "build":2484
    }

View batch transaction commands through the REST API 7.4.1

View batch transaction commands through the REST API 7.4.1

The commands of an uncommitted batch transaction can be viewed through the REST API from an API client with the transaction-show option. Previously administrators could only view commands of a batch transaction through the CLI.

Example

In this example, use the REST API to change the admin timeout of the FortiGate. Before committing the change, check the cached commands to view the pending changes. After committing the change, you cannot view the commands because the transaction is complete.

To view batch transaction commands with the REST API:
  1. From an API client, start a transaction with FortiGate.

    In this example, the transaction ID is 1.

    user@test:~$ curl -k -X 'POST' 'https://<ip address>/api/v2/cmdb?action=transaction-start&vdom=vdom1&access_token=j8Gcs836dQsqbrd9637Qs770s0f13Q' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -d '{
      "timeout": 60
    }'
    
    response:
    {
      "http_method":"POST",
      "revision":"df4217a73f57e09b766605b683fb5caf",
      "revision_changed":false,
      "results":{
        "transaction-id":1
      },
      "vdom":"vdom1",
      "action":"transaction-start",
      "status":"success",
      "http_status":200,
      "serial":"<serial number>",
      "version":"v7.4.2",
      "build":2484
    
    }
  2. Change the admin timeout on the FortiGate for the started transaction.

    For transaction ID 1, the admintimeout is set to 123.

    user@test:~$ curl -k -X 'PUT' 'https://<ip address>/api/v2/cmdb/system/global?access_token=j8Gcs836dQsqbrd9637Qs770s0f13Q' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -H 'X-TRANSACTION-ID: 1' \
      -d '{
      "admintimeout": 123
    }'
    
    response:
    {
      "http_method":"PUT",
      "revision":"c8263664d73eeff0e47db5e142fa5306",
      "revision_changed":false,
      "status":"success",
      "http_status":200,
      "vdom":"vdom1",
      "path":"system",
      "name":"global",
      "serial":"<serial number>",
      "version":"v7.4.2",
      "build":2484
    }
  3. Before committing the commands, check the cached commands.

    The transaction-show results for transaction ID 1 show the uncommitted changes to admintimeout of 123.

    user@test:~$ curl -k -X 'GET'  'https://<ip address>/api/v2/cmdb?action=transaction-show&transaction-id=1&access_token=j8Gcs836dQsqbrd9637Qs770s0f13Q' \
      -H 'accept: application/json'
    
    response:
    {
      "http_method":"GET",
      "revision":"df4217a73f57e09b766605b683fb5caf",
      "results":[
        " config global",
        "  config system global",
        "      set admintimeout 123",
        "  end",
        " end"
      ],
      "vdom":"vdom1",
      "action":"transaction-show",
      "status":"success",
      "http_status":200,
      "serial":"<serial number>",
      "version":"v7.4.2",
      "build":2484
    
    }
  4. Commit transaction ID 1:

    user@test:~$ curl -k -X 'POST'   'https://<ip address>/api/v2/cmdb?action=transaction-commit&vdom=vdom1?access_token=j8Gcs836dQsqbrd9637Qs770s0f13Q'   -H 'accept: application/json'   -H 'Content-Type: application/json'   -d '{
      "transaction-id": 1
    }'
    
    response:
    {
      "http_method":"POST",
      "revision":"df4217a73f57e09b766605b683fb5caf",
      "revision_changed":false,
      "status":"success",
      "http_status":200,
      "vdom":"vdom1",
      "action":"transaction-commit",
      "serial":"<serial number>",
      "version":"v7.4.2",
      "build":2484
    }
  5. Check the commands for transaction 1. An error is returned as expected because transaction 1 is complete. No cached commands are available to be viewed.

    user@test:~$ curl -k -X GET'   'https://<ip address>/api/v2/cmdb?action=transaction-show&transaction-id=1&access_token=j8Gcs836dQsqbrd9637Qs770s0f13Q'   -H 'accept: application/json'            
    
    response:
    
    {
      "http_method":"GET",
      "revision":"df4217a73f57e09b766605b683fb5caf",
      "error":-651,
      "status":"error",
      "http_status":500,
      "vdom":"vdom1",
      "action":"transaction-show",
      "serial":"<serial number>",
      "version":"v7.4.2",
      "build":2484
    }