Cannot assign Department to user

Comments

5 comments

  • Avatar
    Stewart Polley

    Hey Andy,

    I can't see anything wrong here.

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

    Stewart

  • 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:

    id=xxxxx&fields=departments

    ...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/__init__.py", line 138, in _Post
    self.data = self.s.post(posturl, json=kwargs) #This is the code that does the actual call
    File "/usr/lib/python2.7/dist-packages/requests/sessions.py", 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 __init__.py 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.