12

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!

4 Answers 4

11

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)

2
  • thanks for the lead. Unfortunately, my application is only able communicate via REST and doesn't have access to the core Civi application. Still, this lets me know that it is possible, if it isn't already apart of the REST spec.
    – mac
    Commented Aug 12, 2015 at 20:50
  • This would be incredibly useful via API. If a checksum is not currently available in the API, then has anyone explored what it would take to program this? If it is worth building and contributing to the community, or doing an MIH for it. Commented Aug 16, 2015 at 20:44
9
+25

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.

1
  • 2
    Or it could be added as an action in the contact api. E.g. civicrm_api3('Contact', 'generatechecksum', array('id' => $cid)); and it might also be nice to have civicrm_api3('Contact', 'validatechecksum', array('id' => $cid, 'checksum' => 'abc123'));
    – Coleman
    Commented Aug 17, 2015 at 22:00
5

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 :)

1
  • Nice one Jon :)
    – Coleman
    Commented Feb 12, 2019 at 16:02
1

Now with API4 there is \Civi\Api4\Contact::getChecksum() and \Civi\Api4\Contact::validateChecksum() available.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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