Update Users Location via API

46 views
Skip to first unread message

chris...@apps.wylieisd.net

unread,
Apr 10, 2019, 3:02:58 PM4/10/19
to SherpaDesk API
Since the LDAP import does not support importing user locations we are writing a Powershell script which will run each night to go through all user accounts and set the user location based upon a field we have in Active Directory. We have more than 16,000 user accounts and can't depend on our users to set this location manually.

We had requested awhile back that this ability be added to the API so we could issue a PUT /users command to update the location. This is something that I am pretty sure you are aware of. 

In the current API docs, it appears as if updating the location is supported (although it says it's for admins only).


Update existing User (only for ADMINS!)

PUT /users   

{
    "account": 111, // integer, move user to Account with id=111 
    "location": 11, // integer, set Primary Location with id=11, set 0 to clear Primary location
}

 I have been successful in getting the PUT to work for normal user accounts. It does indeed update the users record (seen by issuing a GET before and after the update). However, if you look up the user using the web interface it does not reflect the updated values. It will still show the account and location values that were previously set. 

I could be trying something that is not supported yet. If so, I need to know that it is being addressed as having location information is critical to our operation.

Thanks,
-Chris

Eugene Tolmachev

unread,
Apr 11, 2019, 9:32:59 AM4/11/19
to SherpaDesk API, chris...@apps.wylieisd.net
Hi,

I'll check. Can you give me example user ids and locations,
so I can reproduce this behaviour

Eugene


От: chris.lamb via SherpaDesk API <sherpad...@googlegroups.com>
Отправлено: 10 апреля 2019 г. 22:02
Кому: SherpaDesk API
Тема: Update Users Location via API
 
--
You received this message because you are subscribed to the Google Groups "SherpaDesk API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sherpadesk-ap...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted
Message has been deleted

chrisl...@gmail.com

unread,
Apr 11, 2019, 10:12:21 AM4/11/19
to SherpaDesk API
You can pretty much use any user and location but here are a few I have been working with. The user locations were set manually via the web interface.

-Chris

Deanna Aaron - 1023898

{
"id": 1023898,
"email": {REMOVED},
"firstname": "Deanna",
"lastname": "Aaron",
"FullName": "Deanna, Aaron",
"type": "user",
"fb_staff_id": 0,
"qb_employee_id": 0,
"qb_vendor_id": 0,
"account_id": 16675,
"account_name": "Wylie ISD",
"location_id": 167949,
"location_name": "Educational Svc Ctr",
"xero_contact_id": null,
"opencount": null,
"closedcount": null,
"holdcount": 0
}

Sabah Aarbi - 1016204

{
"id": 1016204,
"email": "{REMOVE}",
"firstname": "Sabah",
"lastname": "Aarbi",
"FullName": "Sabah, Aarbi",
"type": "user",
"fb_staff_id": 0,
"qb_employee_id": 0,
"qb_vendor_id": 0,
"account_id": 16675,
"account_name": "Wylie ISD",
"location_id": 167939,
"location_name": "Achieve Academy",
"xero_contact_id": null,
"opencount": null,
"closedcount": null,
"holdcount": 0
}


Locations
-----------------
[
{
"id": 167939,
"name": "Achieve Academy",
"description": null,
"type": "Building",
"is_default": false,
"is_lastchild": false,
"parent_id": 0,
"sub": null,
"type_id": 0,
"account_id": 0,
"auditor_id": 0,
"last_auditor_name": null,
"tickets_count": 0,
"last_audit_date": null,
"updated_date": null,
"is_audit_completed": false,
"audit_days": 0,
"is_active": true
},
{
"id": 167940,
"name": "Akin Elementary",
"description": null,
"type": "Building",
"is_default": false,
"is_lastchild": false,
"parent_id": 0,
"sub": null,
"type_id": 0,
"account_id": 0,
"auditor_id": 0,
"last_auditor_name": null,
"tickets_count": 0,
"last_audit_date": null,
"updated_date": null,
"is_audit_completed": false,
"audit_days": 0,
"is_active": true
},
{
"id": 167944,
"name": "Cooper Junior High",
"description": null,
"type": "Building",
"is_default": false,
"is_lastchild": false,
"parent_id": 0,
"sub": null,
"type_id": 0,
"account_id": 0,
"auditor_id": 0,
"last_auditor_name": null,
"tickets_count": 0,
"last_audit_date": null,
"updated_date": null,
"is_audit_completed": false,
"audit_days": 0,
"is_active": true
},
{
"id": 167949,
"name": "Educational Svc Ctr",
"description": null,
"type": "Building",
"is_default": false,
"is_lastchild": false,
"parent_id": 0,
"sub": null,
"type_id": 0,
"account_id": 0,
"auditor_id": 0,
"last_auditor_name": null,
"tickets_count": 0,
"last_audit_date": null,
"updated_date": null,
"is_audit_completed": false,
"audit_days": 0,
"is_active": true
},

chrisl...@gmail.com

unread,
Apr 23, 2019, 4:05:27 PM4/23/19
to SherpaDesk API
Eugene,

Have you made any progress on this?

_Chris

chrisl...@gmail.com

unread,
Apr 30, 2019, 9:14:31 AM4/30/19
to SherpaDesk API
Eugene,

Still looking for an update on this. It appears it is still not supported. If you manually set a location via the web interface then you can change the location via an API PUT call. However if no location is set for the user you get a "Procedure or function 'sp_UpdateLogin' expects parameter '@user_title', which was not supplied." error message.

-Chris

Eugene Tolmachev

unread,
Apr 30, 2019, 10:31:37 AM4/30/19
to chrisl...@gmail.com, SherpaDesk API
Hi,

Fixed.

Please try again

Eugene

Совместно мы можем что-то сдвинуть.

> 30 апр. 2019 г., в 16:14, "chrisl...@gmail.com" <chrisl...@gmail.com> написал(а):
>
> Eugene,
>
> Still looking for an update on this. It appears it is still not supported. If you manually set a location via the web interface then you can change the location via an API PUT call. However if no location is set for the user you get a "Procedure or function 'sp_UpdateLogin' expects parameter '@user_title', which was not supplied." error message.
>
> -Chris
>

Lamb, Chris

unread,
May 1, 2019, 8:45:50 AM5/1/19
to Eugene Tolmachev, chrisl...@gmail.com, SherpaDesk API
Still not working. Here is the API call I am making (which is what is in the API Docs):

URL: api.sherpadesk.com/users?id=1007647

Pararmeters:

{
"account_id": 0,
"location_id": 167960,
}

-Chris
You received this message because you are subscribed to a topic in the Google Groups "SherpaDesk API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sherpadesk-api/NLkFfBIbjJg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sherpadesk-ap...@googlegroups.com.

Eugene Tolmachev

unread,
May 2, 2019, 5:20:56 AM5/2/19
to Lamb, Chris, chrisl...@gmail.com, SherpaDesk API
fixed. now works on your data


От: Lamb, Chris <Chris...@wylieisd.net>
Отправлено: 1 мая 2019 г. 15:45
Кому: Eugene Tolmachev; chrisl...@gmail.com
Копия: SherpaDesk API
Тема: RE: [EXTERNAL]Re: Update Users Location via API
 

Lamb, Chris

unread,
May 2, 2019, 9:12:46 AM5/2/19
to Eugene Tolmachev, chrisl...@gmail.com, SherpaDesk API

The API call gives no errors now. However, the location for the user is not updated. If you issue a get for the same user after the put, the data does not change.

 

Chris Lamb
CIO | Wylie Independent School District
951 South Ballard Avenue | Wylie, Texas  75098
P: 972-429-3010 | F:  972-941-6010
chris...@wylieisd.net

Eugene

unread,
Sep 29, 2019, 3:04:47 PM9/29/19
to SherpaDesk API
The syntax on the wiki is wrong.

{     "id": "20", // id of user to update     "email" : "mymail@com", // email of user to update     "account": 111, // integer, move user to Account with id=111      "location": 11, // integer, set Primary Location with id=11, set 0 to clear Primary location }


I added the space after "location" : and after "id" : and it worked.  On the wiki example, there is no space, and it doesn't work like that.

I just successfully updated a user from Postman. Now, to figure out how to make PowerShell do it...

Thanks for the help,

Eugene

unread,
Sep 29, 2019, 3:05:30 PM9/29/19
to SherpaDesk API
So, Postman Canary is capable of generating PowerShell code snippets.

I finally got a working PowerShell script to update the locations.

You have to go under Settings and turn on the "Experimental Codegen mode".  Then, you can get a working query on Postman - click the Code button on the right side and tell it to generate the code.

I had to put the Authorization code encoded Base64 in the Headers and then put the body in raw format like you mentioned.

Probably the hardest part was making it take variable input inside the JSON in PowerShell.

Here's a sample to use the variables $SchoolID and $CSherpaUserID as input

$body = @"
{  
   "location" : "$SchoolID",
   "id" :"$CSherpaUserID"
}
"@

$responsePUT = Invoke-RestMethod 'https://api.sherpadesk.com/users?format=json' -Method 'PUT' -Headers $headers -Body $body
$responsePUT | ConvertTo-Json

You will need the $headers also - but Postman generates that for you as well.

The script unfortunately has a lot of district specific stuff in it, but I could probably strip that out if you'd be interested in having it as a sample.  I'm by no means a PowerShell expert, but it seems to work.  I programmed it to take input from our user sync program called OneSync.  Basically, we're going to use this for when a user moves to a new school - it will run this PowerShell to update their location.

Thank you,



On Wednesday, April 10, 2019 at 10:02:58 PM UTC+3, chris...@apps.wylieisd.net wrote:
Reply all
Reply to author
Forward
0 new messages