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

API PUT produces unexpected result

As part of our first operational use of the API, I need to update two fields dynamically. For trials, I am using php cUrl, modeled on your sample application. I have no problems with GET, but PUT leaves me baffled.

Each time I run the script, the target fields are not changed - but the membership of the target contact goes from "active" to "membership not allocated".

Clearly my code is doing this: but how/why? Can anyone give me a clue as to what is happening?

Also, my debugging script shows a result JSON containing all the target contact's data. Is this as it should be? And can it be prevented (unnecessary data traffic, etc.)?

My cUrl code is (sorry about the bad formatting below):

$accountUrl = "[account]/Contacts/";
$queryParams = array(
'Id' => $contact,
'Field values' => array(
0 => array(
'FieldName' => "fieldname1",
'Value' => 'XXXXX'
1 => array(
'FieldName' => "fieldname2",
'Value' => 'XXXXXX'
$url = $accountUrl.$contact;
$verb = "PUT";

$ch = curl_init();
$headers = array(
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
curl_setopt($ch, CURLOPT_URL, '[account]/Contacts/[contact]');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $verb);
if ($queryParams) {
$jsonData = json_encode($queryParams);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$jsonResult = curl_exec($ch);
if ( !$jsonResult ) {
echo curl_errno($ch) . ': ' . curl_error($ch);

0 votes
Sign in
Sign in with: facebook google
Signed in as (Sign out)

We’ll send you updates on this idea

Hamish McCallum shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →


Sign in
Sign in with: facebook google
Signed in as (Sign out)
  • Hamish McCallum commented  ·   ·  Flag as inappropriate


    This json marks the target contact's membership as not assigned:

    [data_json] => {"Id":"5814141","FieldValues":[{"FieldName":"Trial1","Value":"goatboat"},{"FieldName":"Trial2","Value":"gibberish"}]}

    and this one leaves the membership in place:

    [data_json] => {"Id":"5814141","MembershipEnabled":"true","FieldValues":[{"FieldName":"Trial1","Value":"pigeon"},{"FieldName":"Trial2","Value":"guelph"}]}

    Obviously, if I have to confirm that a membership is enabled, then there'll be two API calls: a GET request, to find out what the enabled status is, and then the PUT.

  • Hamish McCallum commented  ·   ·  Flag as inappropriate

    OK, some progress: changed code slightly and corrected "Field values" typo to "FieldValues". Target field values are now being updated, which is very good!

    And I've worked out that setting CURLOPT_RETURNTRANSFER as false stops the unwanted data dump.

    Unfortunately, the target contact's membership is still being un-assigned each time I run the script.

    The code now looks like this:

Feedback and Knowledge Base