Using XML’s DataService we can query the Referral table for referrals belonging to a contact. This can be used to identify the Affiliate that referred a given contact.
The REST API exposes a way to create Referrals, but I don’t see a way to list referrals for a given contact.
Is there a way to identify the affiliate (if there is one) for a given contact with REST?
In REST API v2, this functionality isn’t implemented yet. It’s one of the gaps we identified thanks to the GitHub repo you set up, and the team is looking into it.
This endpoint allows you to retrieve all referrals for a given affiliate. The documentation hasn’t been updated yet, but we’ll share it soon. In the meantime, here’s an example using curl:
@OmarAlmonte This is great, and useful in other places for us, but the query we’re reaching for is to list the referral/s for a given contact. We’d like to answer the question “who referred this contact”.
Thanks for adding GET /v2/affiliates/{id}/referrals - that’s helpful for affiliate-side reporting!
Likewise, we also need the reverse lookup: given a contact_id, find which affiliate(s) referred them. This is crucial for commission attribution in InfusedWoo and many other integrations.
Current workaround requires XML-RPC dsFind(‘Referral’, …, ‘ContactId’, contactId) which we’re trying to fully migrate away from.
Would it be possible to add either:
GET /v2/referrals?filter=contact_id=={id}, or
GET /v2/contacts/{id}/referrals
This would complete the REST v2 migration path for affiliate tracking.
Hi @Mark_Joseph, thanks for the feedback! I’ve added this to the known issues tracker. I’ll keep you posted and share an update as soon as we have more information.
Hi @Todd_Stoker, @Timothy_Withers, and @Mark_Joseph. We’ve added a new filter to GET /v2/affiliates to help answer the “who referred this contact” use case directly in REST v2:
referral_contact_id – returns a list of all affiliates who referred the given contact.
Example:
GET /v2/affiliates?filter=referral_contact_id==12345
The documentation hasn’t been updated yet, but you can start using this filter now.
I just tested GET /v2/affiliates?filter=referral_contact_id==19 against our sandbox and it’s currently returning 400 — “Invalid filter field: referral_contact_id”.
The same contacts return correct referral data via XML-RPC dsFind('Referral', 'ContactId'), so the data is there — it looks like the filter just hasn’t been deployed yet.
For context, our use case is: given a contact ID, find which affiliate referred them so we can attach the affiliate to the order. The XML-RPC pattern is dsFind('Referral', 1000, 0, 'ContactId', $contactId, ['AffiliateId']) — the new referral_contact_id filter on /v2/affiliates would be a perfect replacement.
That new filter should cover your use case perfectly, it’s designed exactly for “given a contact ID, find which affiliate(s) referred them.”
I’m not certain why it’s returning 400 in your sandbox, but here’s an example cURL you can use to see the affiliate(s) that referred the contact ID sent in the referral_contact_id query param: