Freshsales Logo freshchat

Start a new topic

Import departments via API

I need to import a huge list of companies in FreshService. It is possible to import via a API in JSON

I use what is provided bij FreshService:


{

    "itil_department":{

        "name":"SuperNova",

        "description":"Spaceship Manufacturing Company",

        "department_users_attributes":{

            "head_id":"34"

        }

    }

 

}

It is possible to put one company at the time, but I would like to put many of them in at once. If I try to do that, is fails. Somebody an idea how to solve this?


Kind regards

1 Comment

Below is inelegant but working PowerShell script (I'm using version 5.0, lower versions would probably work, how low I'm not sure).  Variable $depts holds multiple JSON body strings, foreach iterates over each using RESTful API (v1) to create department.  Illustrative example only, scaling this up to hundreds/thousands of departments would be a pain, but $depts could be read from an external file of almost any type with appropriate changes to rest of script.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$thekey = [convert]::ToBase64String([text.encoding]::ASCII.getbytes('yourApiKey'))
$depts = '{"itil_department":{"name":"SuperNova1","description":"Spaceship Mfg Company1", "head_id":"500001"}}','{"itil_department":{"name":"SuperNova2","description":"Spaceship Mfg Company2", "head_id":"500002"}}','{"itil_department":{"name":"SuperNova3","description":"Spaceship Mfg Company3", "head_id":"500003"}}'
$headers = @{}
$headers.Add('authorization', ("Basic {0}" -f $thekey))
$headers.Add('content-type', 'application/json')
$url = 'https://yourCompany.freshservice.com/itil/departments.json'
foreach ($d in $depts) {
    Invoke-RestMethod -Method post $url -Headers $headers -Body $d
}

 


Login or Signup to post a comment