Is there a way to view or generate a Contact's checksum via the REST API?
I'm looking to use the checksum to provide relevant form links, etc., but need to get it programmatically on a Contact basis. Any and all insight is appreciated. Thanks!
I have never seen the checksum available in the API.
I have successfully obtained it programmatically though with code similar to:
$cs = CRM_Contact_BAO_Contact_Utils::generateChecksum($contact_id);
(This snippet is adapted from core code in CRM/Utils/Token.php)
I'm pretty certain you can't get a checksum from the standard API. However, you should write (or commission) an extension to provide a checksum API. The API would basically be a wrapper around the code that DaveD suggested, and you can read documentation here on how to use Civix to generate an API in your extension.
civicrm_api3('Contact', 'generatechecksum', array('id' => $cid));
and it might also be nice to have civicrm_api3('Contact', 'validatechecksum', array('id' => $cid, 'checksum' => 'abc123'));
I needed this exact functionality, so I wrote the extension that provides it, com.megaphonetech.checksums. I used Coleman's comment above as my spec :)
Now with API4 there is \Civi\Api4\Contact::getChecksum()
and \Civi\Api4\Contact::validateChecksum()
available.