Please Help with updating user info / Python SDK

i am trying to update user EXs through the API and the closest way i got is patch_user() in here but how i pass body parameter

body = PureCloudPlatformClientV2.UpdateUser() # UpdateUser | User

try:
    # Update user
    api_response = api_instance.patch_user(user_id, body)
    pprint(api_response)
except ApiException as e:
    print "Exception when calling UsersApi->patch_user: %s\n" % e

i tried python dictionary and that didn't work nor JSON

another important question is there an away to update the addresses part only instead of patching all user info and if so could you show me example code

Many Thanks

what error are you getting? With a patch you should be able to update just the information you need to change by just passing that info into the request UpdateUser object

Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json', 'Content-Length': '170', 'Connection': 'keep-alive', 'Date': 'Wed, 10 Oct 2018 23:21:56 GMT', 'inin-ratelimit-count': '52',
'inin-ratelimit-allowed': '180', 'inin-ratelimit-reset': '45', 'ININ-Correlation-Id': '0ba0b4b1-3dc8-43bc-b263-ac0df78100e4', 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 28f8194b09e7a5cef32fc3dbac5538f2.cloudfront.net (CloudFront)', 'X-Amz-Cf-Id': 'waE7E2udops2Pdqlk0r6fOX7oEMDrbhNQsUxo0EoOcDMOSKSyEwFhA=='})
HTTP response body: {"status":400,"code":"bad.request","message":"The requested operation failed with status 400","contextId":"0ba0b4b1-3dc8-43bc-b263-ac0df78100e4","details":[],"errors":[]} ```


`could you show me an example code how to update Name or one field  
also how i create the user object ?`

When updating a user, you need to set the version to the current version of the user, so first you have to get the user config to find what that version is

import time
import PureCloudPlatformClientV2
from PureCloudPlatformClientV2.rest import ApiException
from pprint import pprint

PureCloudPlatformClientV2.configuration.access_token = 'AUTH TOKEN HERE'

# create an instance of the API class
api_instance = PureCloudPlatformClientV2.UsersApi()
user_id = 'f8ca529b-4fcb-4196-a34e-4ae6f7d1c974' # str | User ID

currentuser = api_instance.get_user(user_id)

body = PureCloudPlatformClientV2.UpdateUser() # UpdateUser | User
body.name = user_id
body.name = "New Name"
body.version = currentuser.version
try:
    # Update user
    api_response = api_instance.patch_user(user_id, body)
    pprint(api_response)
except ApiException as e:
    print "Exception when calling UsersApi->patch_user: %s\n" % e

Thank you Kevin, it works for most parts but i am having issues with addresses though

i am using this code and let me know what i am doing wrong in here please

api_instance = PureCloudPlatformClientV2.UsersApi()
user_id = genesys_user.id # str | User ID
body = PureCloudPlatformClientV2.UpdateUser()
body = PureCloudPlatformClientV2.UpdateUser() # UpdateUser | User
body.id = user_id
body.title = "New Cool title"
body.version = genesys_user.version
body.addresses =  [{'address': '+18586099000', 'display': '+1 858-609-7000', 'extension': None,'media_type': 'PHONE','type': 'WORK'}]

 api_response = api_instance.patch_user(user_id, body)

but i am getting this error

Exception when calling UsersApi->patch_user: (500)
Reason: Internal Server Error
HTTP response headers: HTTPHeaderDict({'Content-Type': 'application/json', 'Content-Length': '180', 'Connection': 'keep-alive', 'Date': 'Thu, 11 Oct 2018 18:37:16 GMT', 'ININ-Correlation-Id': '935d4361-18a5-4dd1-ace5-743967016a8e', 'inin-ratelimit-count': '87', 'inin-ratelimit-allowed': '180', 'inin-ratelimit-reset': '40', 'Cache-Control': 'no-cache, no-store, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 4491423cc0ea94bb70fcfbc7ad85f8ff.cloudfront.net (CloudFront)', 'X-Amz-Cf-Id': 'CjSkBFKo8j9DWiDWzIU_pEZX7FspzGv1OOJ5-VqplvsTQc06PWEUXQ=='})
HTTP response body: {"status":500,"code":"internal.server.error","message":"The requested operation failed with status 500","contextId":"935d4361-18a5-4dd1-ace5-743967016a8e","details":[],"errors":[]}

Address isn't a dict, it is a List of Contact objects

updateuser = PureCloudPlatformClientV2.UpdateUser()
updateuser.version = currentuser.version

newaddress = PureCloudPlatformClientV2.Contact()
newaddress.address = "3172222222"
newaddress.media_type = "PHONE"
newaddress.type = "WORK"
updateuser.addresses = [newaddress]

Thank you Kevin !
it works now

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.