API V2 authentication and sample routines in Python
Hi,
I'm trying to integrate my Wild Apricot database into a standing Python program. If somebody has already written the V2 API authentication and some routines in Python, can they share so I can leverage?
Thanks in advance.
Sample python code on github: https://github.com/WildApricot/ApiSamples/tree/master/python
-
Eric commented
The example code at:
https://github.com/WildApricot/ApiSamples/tree/master/python
does not compile with either python2 or python3. It appears to want to use the python3 urllib library, but complains about:File "/home/eric/wild_apricot/ApiSamples/python/WaApi.py", line 70, in authenticate_with_contact_credentials
request = urllib.request.Request(self.auth_endpoint, encoded_data, method="POST")
TypeError: __init__() got an unexpected keyword argument 'method'"method=xxx" is not an argument for urllib.request.Request(). So apparently it actually does <i>not</i> work.
-
Chris Hailey commented
Hi,
I have been using a Python V2.7 adaptation of your sample code. It was working fine until about a week ago (14th June), then overnight it stopped working, raising an exception when I tried to print out the authentication token details, which is an ApiObject instance:
self._token = WaApiClient._parseResponse(response)
if self._verbose: _statusErrMsg('info', 'authentAppKey()', self._token)
The code is failing when trying to execute the __str__ method of the ApiObject because it considers the data invalid: File "D:\ourData\progLan\python\crhWA2a.py", line 418, in __str__ return json.dumps(self.__dict__) File "C:\Python27\lib\json\__init__.py", line 231, in dumps return _default_encoder.encode(obj) File "C:\Python27\lib\json\encoder.py", line 201, in encode chunks = self.iterencode(o, _one_shot=True) File "C:\Python27\lib\json\encoder.py", line 264, in iterencode return _iterencode(o, 0) File "C:\Python27\lib\json\encoder.py", line 178, in default raise TypeError(repr(o) + " is not JSON serializable")TypeError: {"AvailableScopes": ["account_view", "contacts_view", "event_registrations_view", "events_view", "finances_view", "membership_levels_view"], "AccountId": 123456} is not JSON serializable
This started the day before the new API V2 authentication changes were applied. I have waited a week and since modified the code to use the new authentication protocol but the error persists. This is not a significant problem for me because I have trapped the error, but should it be raised in the first place? I use the same technique in several other methods but none of them trigger this exception so it is probably specific to the authentication token data.
-
Dmitry Smirnov commented
Hi,
I've just published sample python code on github: https://github.com/WildApricot/ApiSamples/tree/master/python
I'm not a python guru and this code is not a masterpiece, however it works. There are 2 files: WaApi.py is a python module, which helps to work with API
ApiTest.py is a demo, which downloads account information, downloads 10 active members and print their details creates new contact archives this contact