Cannot assign Department to user



  • Avatar
    Stewart Polley

    Hey Andy,

    I can't see anything wrong here.

    It might be best to send an email through to with the exact JSON you're doing and let me know which account it's for, and I'll check it out.


  • Avatar
    Andy Tan

    Sent :)

  • Avatar
    Andy Tan

    After much testing (and hair-pulling), I figured it out! :)

    Short answer:

    I discovered that this JSON works for me when I use the provided Python API code to connect:

    {'fields[departments]': 'Test||Sub||Pos', 'id': 'xxxxx'}

    Long answer:

    By using Postman and Fiddler, I found out that the Elvanto servers only accept requests of content-type "application/x-www-form-urlencoded", and when Python's Requests library does the URL encoding of my previous JSON string - {'fields': {'departments': ['Test||Sub||Pos']}, 'id': 'xxxxx'} - the escaped output becomes:


    ...which is incorrect.

    So I used Postman to construct a request that definitely works, and then parsed the URL encoded string back to a Python data structure and discovered it's simply: 

    {'fields[departments]': 'Test||Sub||Pos', 'id': 'xxxxx'}


    Hope this would be helpful for other Elvanto-integrators using Python :)

  • Avatar
    Stewart Polley

    That's unusual. I was able to use the Python API Wrapper fine and got it.

    Can you share your version of python, requests and urllib3?

  • Avatar
    Andy Tan

    Hi Stewart!

    I'm using Python version 2.7.6, requests version 2.2.1, and urllib3 version 1.7.1.

    Actually, when I use the default ElvantoAPI directly from a pip install, I get this error:

    File "/usr/local/lib/python2.7/dist-packages/ElvantoAPI/", line 138, in _Post =, json=kwargs) #This is the code that does the actual call
    File "/usr/lib/python2.7/dist-packages/requests/", line 509, in post
    return self.request('POST', url, data=data, **kwargs)
    TypeError: request() got an unexpected keyword argument 'json'

    In order for me to get it working, I need to edit the file in ElvantoAPI to get rid of the json= on line 138.

    I'm actually more a .NET dev than a Python dev... so there's a chance that I might actually be doing something wrong. But I'm just restricted to Python on this hosted server that we use :(

Please sign in to leave a comment.