Kaseya Community

REST API - "Add User"

  • Before I embark on attempting this, thought I'd ask and see if anyone has done it yet ... not reinventing wheels if I do not have to do so. Has anyone made new Kaseya user accounts using the API via PowerShell?

    I can pull all sorts of data and push it to Excel, SQL, Access, etc all day long, thanks in large part to Liam Kemp's previous work (Much thanks BTW).

    From what I can tell, I am building the JSON correctly, at least my Json matches what comes back from the GET (/system/users)  sans the password string and creation date ... and I don't think disabled matters ...

    ---- My New User as JSON

    {
    "AdminName": "TestUserName",
    "DefaultStaffDepartmentId": 71741269613387425417915943,
    "FirstName": "FirstTest",
    "LastName": "LastTest",
    "Admintype": 1,
    "DefaultStaffOrgId": 96218191882692224258251423,
    "AdminRoleIds": [
    213551341
    ],
    "AdminPassword": "P@55w05d!",
    "AdminScopeIds": [
    "11276111737165513687917243",
    "42842411461562514219131755",
    "94151179132166194134272783",
    "21817525121555339238319139"
    ],
    "Email": "TestGuy@testdomain.com"
    }

    -----User from system JSON

    {
    "UserId": 89801949,
    "AdminName": "username",
    "AdminPassword": "cover9cb1adfe773888d59c53f2f7f7469f55dcc7ed0f67179d25668ab2162f54c76e",
    "Admintype": 1,
    "DisableUntil": null,
    "CreationDate": "2018-04-03T11:06:01.84",
    "AdminScopeIds": [
    "11276111737165513687917243",
    "42842411461562514219131755",
    "94151179132166194134272783",
    "21817525121555339238319139"
    ],
    "AdminRoleIds": [
    213551341
    ],
    "FirstName": "user",
    "LastName": "name",
    "DefaultStaffOrgId": "96218191882692224258251423",
    "DefaultStaffDepartmentId": "71741269613387425417915943",
    "Email": "username@domain.com
    "Attributes": null
    }

    The error I get back is, 

    Invoke-RestMethod : {
    "Result": [
    "AdminScopeIds can not have more than one record"
    ],
    "ResponseCode": 0,
    "Status": "OK",
    "Error": "None"
    }

    .... Not sure how else to get all those scopeIDs in there. Having to go into the GUI and add a bunch of scopes defeats the purpose of all this.

    Anyone have any ideas?

    Thanks,

    *jg

  • Off hand I would say to try it with just one in the ScopeID and see if that succeeds first.  

    The documentation certainly makes it *sound* like this would accept multiples so you may have hit on a bug. Otherwise my only guess is that they only accept one during the create and set that as their default scopeid, then you'd need to determine their UserID after adding, and then using the Updateuser API to add the other ScopeID's.

    I haven't dug into the API when it comes to adding users yet.  

  • I did some testing with the swagger interface and seemingly confirmed my suspicion.  So even though the documentation shows that can be an array, it will only accept one value on creation.  AdminRoleIds is exactly the same.  So you probably have to add the user, and the separately query for their UserID and use that with the Update User to add the other role ids.

    help.kaseya.com/.../9050000

  • Yep - Discovered that too ... can only take one ScopeID ...

    So - When we do make a new user, we just get back a success message, meaning I have no idea what the user ID is. So, I'll GET /system/users, find the one with the same AdminName, grab the UserID and attempt the update user call and feed in the additional ScopeIDs.

    Ref: help.kaseya.com/.../9040000

    I will play with that this evening and see what happens.

  • Not much success ....

    {

     "ResponseCode": 500,

     "Status": "Failed",

     "Error": "Method not found: 'System.String[] Kaseya.SystemTab.Data.DataAccess.Users.IUserDataProvider.UpdateUserAdminType(Kaseya.SystemTab.Models.User)'."

    }

    Will play more tomorrow.

  • I played around with the Swagger UI, and I get the exact same error attempting to update *any* user.  I'm thinking you found a bug in their API.

  • Not supported in 9.4, confirmed with support. Documentation is wrong for 9.4.

    9.5 has a method "Add User to Scope" --> help.kaseya.com/.../9050000

    So guess I am done with this adventure.

    Thanks for your help Jonathan.

    *jg