Legacy Dev Forum Posts

 View Only

Sign Up

Please Help with updating user info / Python SDK

  • 1.  Please Help with updating user info / Python SDK

    Posted 06-05-2025 18:08

    raltaie | 2018-10-11 17:19:53 UTC | #1

    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


    KevinGlinski | 2018-10-11 17:21:02 UTC | #2

    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


    raltaie | 2018-10-11 17:38:49 UTC | #3

    `Exception when calling UsersApi->patch_user: (400) 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 ?


    KevinGlinski | 2018-10-11 18:04:54 UTC | #4

    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

    apiinstance = PureCloudPlatformClientV2.UsersApi() userid = 'f8ca529b-4fcb-4196-a34e-4ae6f7d1c974' # str | User ID

    currentuser = apiinstance.getuser(user_id)

    body = PureCloudPlatformClientV2.UpdateUser() # UpdateUser | User body.name = user_id body.name = "New Name" body.version = currentuser.version try:

    Update user

    apiresponse = apiinstance.patchuser(userid, body) pprint(apiresponse) except ApiException as e: print "Exception when calling UsersApi->patchuser: %s\n" % e


    raltaie | 2018-10-11 18:48:52 UTC | #5

    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

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

    apiresponse = apiinstance.patchuser(userid, body)

    but i am getting this error

    Exception when calling UsersApi->patchuser: (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': 'CjSkBFKo8j9DWiDWzIUpEZX7FspzGv1OOJ5-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":[]}


    KevinGlinski | 2018-10-12 13:22:31 UTC | #6

    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]


    raltaie | 2018-10-12 22:53:23 UTC | #7

    Thank you Kevin ! it works now


    system | 2018-11-12 22:53:26 UTC | #8

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


    This post was migrated from the old Developer Forum.

    ref: 3716