How can we make it easier for you to develop on top of Wild Apricot?

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.

0 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)

    We’ll send you updates on this idea

    czarchuaczarchua shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    3 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • EricEric commented  ·   ·  Flag as inappropriate

        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 HaileyChris Hailey commented  ·   ·  Flag as inappropriate

        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.

      • DmitryDmitry commented  ·   ·  Flag as inappropriate

        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

      Feedback and Knowledge Base

      Wild Apricot Inc. 144 Front Street West Suite 725, Toronto, Ontario, Canada M5J 2L7