1

I am having two issues w/ the REST api via curl.

1) API is ignoring json attribute. If I do not urlencode, I get a "Unable to decode supplied JSON" return msg. When I do encode, as shown below, I get past issue, but it seems to ignore any of the conditions set in json attrib. It just return all contacts, w/out restricting by external_identifier or applying return filters set in json object.

$curl_post_data = [
    'debug' => 1,
    'version' => 3,
    'entity' => 'Contact',
    'action' => 'get',
    'json' => urlencode (json_encode ( ["sequential"=>1,"return"=>"id,do_not_mail","external_identifier"=>777] )),
    'api_key' => '1234',
    'key' => '1234',
];

If I take out conditions & filters out of json attrib, it works fine :

$curl_post_data = [
    'debug' => 1,
    'version' => 3,
    'entity' => 'Contact',
    'action' => 'get',
    'json' => 1,
    'api_key' => '1234',
    'key' => '1234',
    'external_identifier' => 777,
    'return'=> 'id,do_not_mail'
];

However, everyone else seems to be using this json attrib. I would like to get that working.

2) Second issue is chaining.

$curl_post_data = [
    'debug' => 1,
    'version' => 3,
    'entity' => 'Contact',
    'action' => 'get',
    'json' => 1,
    'api_key' => '1234',
    'key' => '1234',
    'external_identifier' => 777,
    'return'=> 'id,do_not_mail',
    'api.Contact.create' => urlencode (json_encode(['do_not_mail'=>0]))
];

Using api.Contact.create / replace, etc will trigger an undefined field error : undefined_fields":["api_Contact_create"].

I am json_encoding the field value in this example, but get the same issue by just passing an array. It just doesn't seem to recognize the chaining directive at all.

Any help much appreciated.

1

Not everyone else use only the json, I find it easier to read and fix to use separate params ;)

I think the error is on the json you provide is not correct. Instead of:

["sequential"=>1,"return"=>"id,do_not_mail","external_identifier"=>777]

it should be

{"sequential":1,"return":"id,do_not_mail","external_identifier":777}

  • I also do not like or use the json, I also prefer the separate params. Must be an age thing Xavier :-) – ErikH - CiviCooP Jan 3 at 12:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.