Technical Tip: Manage metadata variables Using JSON API
Description
This article describes how to manage (get, create, add/update mapping, and delete) Metadata Variables in FortiManager using the API.
Scope
FortiManager.
Solution

Get existing metadata variables:
{
"method": "get",
"params": [
{
"url":"/pm/config/adom/{{ADOM}}/obj/fmg/variable/"
}
],
"id": 1,
"verbose": 1
}
Create a new variable:
{
"method": "add",
"params": [
{
"url": "pm/config/adom/{{ADOM}}/obj/fmg/variable",
"data": {
"type": "normal",
"name": "Test_Variable",
"value": "<VALUE>",
"description": "variable",
"dynamic_mapping": [
{
"_scope": [
{
"name": "<DEVICE_NAME>",
"vdom": "<VDOM>"
}
],
"value": "<Mapping_Value>"
}
]
},
"revision note": "adding new variable"
}
],
"id": "1"
}
The 'type' field is supported in FortiManager v7.6.4 and later. Set its value to 'normal' for standard metadata variables or to 'password' for sensitive information that should be obfuscated. Refer to ADOM-level metadata variables.
Add or update mapping:
To add a mapping for a new device to an existing metadata variable, use the 'add' method in the API request below.
{
"method": "add",
"params": [
{
"data": {
"_scope": {
"name": "<DEVICE_NAME>",
"vdom": "<VDOM>"
},
"value": "<VALUE>"
},
"url": "/pm/config/adom/{{ADOM}}/obj/fmg/variable/<METADATA_VARIABLE_NAME>/dynamic_mapping"
}
],
"id": 1
}To update the mapping of an existing device in an existing metadata variable, use the same API request as above, but set the method to 'update'.
"method": "update"To add mapping for a Device Group, under the scope remove the VDOM and for name set the device group name.
"_scope": {
"name": "<Device_Group_Name>",
},
Delete a metadata variable:
{
"method": "delete",
"params": [
{
"url": "pm/config/adom/{{ADOM}}/obj/fmg/variable",
"confirm": 1,
"filter": [
"name",
"in",
"<Name_Of_Variable>"
]
}
],
"id": "4",
"verbose": 1
}
Troubleshooting:
The following commands can be used on the FortiManager CLI to debug the API calls:
diagnose debug enable
diagnose debug service main 255
diagnose debug service main 255If the delete API fails and shows 'used', check where it is used by referring to Technical Tip: Find and replace an address object using the JSON API.
Postman API Collection for quick use: Metadata Variables.
Related documents:
