I’am using the ansible directormodul for this. Ansible modules for Icinga Director
You need to use the director rest api and not the icinga2 api. If i want to add vars with Powershell f.e. i read out the existing vars into an array, add the new and write them back.