Skip to main content
farhanahmed
Staff
Staff
December 26, 2024

Technical Tip: How to create template group using JSON API

  • December 26, 2024
  • 0 replies
  • 462 views
Description This article describes how to create template groups, add templates to it and assign to a device using FortiManager API.
Scope FortiManager.
Solution
  1. Get the existing Template Group(s):

    {
     "method": "get",
        "params": [
            {
                "url": "pm/tmplgrp/adom/ADOM_NAME"
            }
        ],
        "session": "{{session}}",
        "id": 1

    }

 

Sample output:

 

1.png

 

  1. Create a new Template Group:

{
  "id": "1",
    "method": "add",
    "params": [
        {
            "url": "pm/tmplgrp/adom/ADOM_NAME",
            "data": [
                {
                    "name": "TEMPLATE_NAME",
                    "type": "tmplgrp",
                    "scope member": [],
                    "template group setting": {
                        "description": "Test template group",
                        "cliprofs": [
                            "test_cli_grp"
                        ],
                        "fspprofs": [
                            "test-fsw"
                        ],
                        "fxtprofs": [
                            "test-fex"
                        ],
                        "wtpprofs": [
                            "test-ap"
                        ],
                        "templates": [
                            "1__test-system",
                            "3__test--tw",
                            "4-1__test-ipsec",
                            "4-1240__test-bgp",
                            "4-2__test-static-route",
                            "5__test_sdwan"
                        ]
                    }
                }
            ]
        }
    ],
    "session": "{{session}}"

}


Sample output:

 

1.png

 

Note:

'cliprofs': CLI Templates.
'wtpprofs': FortiAP Templates.
'fspprofs': FortiSwitch Templates.
'fxtprofs': FortiExtender Templates.
'templates': This includes the rest of the templates.

 

Codes for the templates are below:

1__ = System template.
3__ = Threat Weight Template.
4-1__ = IPSec Template.
4-1240__ = BGP Template.
4-2__ = Static Route Template.
5__ = SD-WAN Template.

 

  1. To assign the Template Group to a device (or a device group), the initial 'add' request can be modified to add a scope member or create a new 'update' request:

{
  "id": "1",
    "method": "update",
    "params": [
        {
            "url": "pm/tmplgrp/adom/ADOM_NAME",
            "data": [
                {
                    "name": "TestTemplateGroup",
                    "type": "tmplgrp",
                    "scope member": [
                        {
                            "name": "DeviceGroup"
                        },
                        {
                            "name": "FortiGate-60F",
                            "vdom": "root"
                        }
                    ]
                }
            ]
        }
    ],
    "session": "{{session}}"
}


Sample output:

 

1.png

 

Note:

Specify the device group 'name' to assign to a device group. For individual devices, specify the 'Name' and the 'vdom'.

 

Troubleshooting:

The following commands can be used on the FortiManager CLI to debug the API Calls:

 

diagnose debug service rpc-auth 255

diagnose debug service main 255

 

Related documents:

Technical Tip: Using FortiManager API

Fortinet Development Network (FNDN) - FortiManager

Technical Tip: How to create IPSec Template and assign to a device using JSON API

Technical Tip: How to create SD-WAN Template and assign to a device using JSON API

Technical Tip: Managing the JSON API call with Postman and how to delete, create and update an ADOM... 

Thought Leadership. Security Summit. Thursday, November 12th, PGA National Resort, Palm Beach Gardens, FL.
Thought Leadership. Security Summit. Thursday, October 8th. Disney's Grand Californian Hotel & SPA, Anaheim, CA.
Security Operations Summit: Modernize SecOps. Operate AI-Native.AMER: November 4 | 9:00 AM PST. India and SAARC: November 5 | 10:00 AM IST. EMEA: November 5 | 10:30 AM CET. APAC: November 5 | 11:00 AM SGT