Kaseya Community

add organization via RESTAPI failing

This question is answered

Hi All,

I'm hoping that someone can help point me in the right direction here.

I am trying to add an organization to our kaseya server using the RESTAPI and php curl, however I keep getting this returned :

2019/11/01 : 08:38 :{
"Result": [
"OrgRef is required",
"OrgName is required",
"DefaultDepartmentName is required",
"DefaultMachineGroupName is required"
],
"ResponseCode": 400,
"Status": "Failed",

from the kaseya documentation it looks like you submit the POST data in json format. All those fields that say required I have the info for and it is in my json string that is posted to the API, the json string looks like this :

{"OrgName":"zwp50","OrgRef":"zwp50","DefaultDepartmentName":"unassigned","DefaultMachineGroupName":"unassigned","ContactInfo":{"PrimaryEmail":"jack@soso.com"}}

Which to me looks to be in the right format and looks the same minus some of the fields that I don't need right now, but the required fields as per the returned message are present and have a value.

The code I'm using to make the POST request is the following, the first part of the code creates the post data in json format from the supplied variables and the curl code posts the request to Kaseya.  :

//creates the post data

$info = json_decode($json, true);
$id = $info['id'];
$orgname = "zwp" . $id;
$email = $info['email'];

$data = json_encode(array(
"OrgName" => $orgname,
"OrgRef" => $orgname,
"DefaultDepartmentName" => "unassigned",
"DefaultMachineGroupName" => "unassigned",

"ContactInfo" => array(
"PrimaryEmail" => $email,
)
));

//Custom auth header

$headers = array (

'Authorization : Bearer ' . $token
);

//Curl Post Connection

$vsa = "https://soso.com/api/v1.0/system/orgs";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $vsa);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);


$output = curl_exec($ch);
curl_close($ch);

At this point I am lost as to why the API returns saying it requires the data that I am providing it. I do not get any PHP errors so I don't think it is my POST code that's failing, all I can think of at the moment is it must be the way in which I am building the $data string that is sent through to the API.

If anyone is able to assist with this, it would be highly appreciated.

Regards, 

 

Verified Answer
  • You must specify "OrgId: 0" along with the OrgName and OrgRef.

    Our automation for creating orgs and the machine.group structure uses this extensively. Looking at my source, the OrgID:0 is hard coded in the JSON string because without it nothing worked.

    Our headers also include "Content-Type: application/json" in addition to the authorization.

    Glenn

All Replies
  • You must specify "OrgId: 0" along with the OrgName and OrgRef.

    Our automation for creating orgs and the machine.group structure uses this extensively. Looking at my source, the OrgID:0 is hard coded in the JSON string because without it nothing worked.

    Our headers also include "Content-Type: application/json" in addition to the authorization.

    Glenn

  • Hi Glenn

    Thanks for the assist. my issue was the content-type header part. When I added it the first time I had a space in between the type and the colon and that caused it to fail with a header error.

    Gareth