Developers

ReferralCandy API

A simple interface with JSON-formatted responses to integrate your store with the ReferralCandy referral platform. Register purchases, enroll advocates, query referrals and manage rewards.

Base URLhttps://my.referralcandy.com/api/v2.2/

Introduction

The ReferralCandy API provides a simple interface withJSON-formatted responses to integrate your store with the ReferralCandy referral platform.

ReferralCandy API calls are made to the following URL:

https://my.referralcandy.com/api/v2.2/some-method.json

Please note that all API input should be encoded in UTF-8.

Please note that all timestamps used in our API must be in Unix time format (seconds). For example, use 1625078400 for June 30, 2021, 00:00:00 UTC. Do not use milliseconds (e.g., 1625078400000) or ISO 8601 (e.g., 2021-06-30T00:00:00Z).

Authentication

Each call to the ReferralCandy API requires the sending of the currentUNIX timestamp, Access ID and signature parameters. Your API Access ID can be found on your account settings page. The signature parameter is generated from your API Secret Key which can also be found on your account settings page.

To generate the signature for a particular call to the API, carry out the following steps:

  1. Gather the API call parameters into an array of strings of the format "parameter_name=parameter_value".
  2. Sort the name/value pairs in the array.
  3. Join the array elements into a string.
  4. Prepend the API Secret Key to the string to form a combined string.
  5. The signature is the MD5 of this combined string.

A sample signature calculation is as follows:

  1. ["timestamp=1296664909", "accessID=acihijaklscj", "name=john"]
  2. ["accessID=acihijaklscj", "name=john", "timestamp=1296664909"]
  3. "accessID=acihijaklscjname=johntimestamp=1296664909"
  4. "APISECRETKEYaccessID=acihijaklscjname=johntimestamp=1296664909"
  5. signature = MD5("APISECRETKEYaccessID=acihijaklscjname=johntimestamp=1296664909") = "04535fe455e9f77a90c06e81d7888569"

Response Codes

The ReferralCandy API uses standard HTTP status codes to indicate success or failure of API calls.

HTTP CodeMeaning
200API call was successful.
400You've made an error in your request. See the message field in the response for details.
401Authentication credentials provided were incorrect.
403Forbidden. Authentication was successful but the method is not available. See the message and reason fields for details.
404Unknown API method.
500A temporary internal server error.

API Methods

Verify Method GET

Overview

This method lets you verify that authentication for your API calls is set up correctly. This method is not available when the account is suspended and will return a HTTP 403 Forbidden status code.

Endpoint

GEThttps://my.referralcandy.com/api/v2.2/verify.json

Input Parameters

FieldDescriptionRequired
timestampUNIX timestamp of API call.yes
accessIDAPI Access ID.yes
signatureCalculated signature.yes

Output Parameters

FieldDescription
messageA message indicating the outcome of the API call.
reasonFurther information provided about the response. This field is returned only in certain cases.

Sample Result

{"message":"Verification Ok"}

Campaigns Method GET

Overview

This method returns a list of campaigns for your account.

Endpoint

GEThttps://my.referralcandy.com/api/v2.2/campaigns.json

Input Parameters

FieldDescriptionRequired
timestampUNIX timestamp of API call.yes
accessIDAPI Access ID.yes
signatureCalculated signature.yes

Output Parameters

FieldDescription
campaigns

Array of campaigns in your account

FieldDescription
campaign_idUnique identifier for the campaign that can be used for querying other api
campaign_nameName of the campaign.
join_urlPublic URL customers can visit to join the campaign.
campaign_statePossible values: ACTIVE | PAUSED | STOPPED
messageA message indicating the outcome of the API call.

Sample Result

{"message": "Success", "campaigns": [{"campaign_id": 123, "campaign_name": "Summer Referral Campaign", "join_url": "https://abc.refr.cc/join/summer-campaign","campaign_state": "ACTIVE"}]}

Purchase Method POST

Overview

This method lets you register a new purchase at your store. This method is not available when the account is suspended and will return a HTTP 403 Forbidden status code.

Endpoint

POSThttps://my.referralcandy.com/api/v2.2/purchase.json

Input Parameters

FieldDescriptionRequired
first_nameCustomer's first name.yes
last_nameCustomer's last name.no
emailCustomer's email address.yes
localeCustomer's preferred language. Defaults to campaign's default language if it is not set or not available to the campaign. This is a complete list of valid values (ISO 639-1 language code): en, fr, de, es, it, ja, nl, ru, zh-CN, zh-HK, zh-TW, da, no, sv, pt-BR.no
discount_codeDiscount code used in the order. Blank if no discount code was used.yes if discount code was used
accepts_marketingWhether the customer opted in to marketing (true/false). Defaults to true.no
order_timestampUNIX timestamp of order.yes
browser_ipIP address of customer when making the purchase.yes
user_agentUser agent string of the customer's web browser.yes
invoice_amountTotal invoice amount for this purchase.yes
currency_codeISO 4217 currency code used in order invoice (e.g. USD, GBP, INR).yes
external_reference_idAn ID that can be used to track this purchase externally.no
referrer_idAn optional referrer identifier you can add to identify the referrer of this purchase. This is usually the AIC parameter ReferralCandy appends when a new customer clicks a referral link to get to the merchants store. The referrer_id will be used to help identify who referred this purchase.no
timestampUNIX timestamp of API call.yes
accessIDAPI Access ID.yes
signatureCalculated signature.yes

Output Parameters

FieldDescription
messageA message indicating the outcome of the API call.
reasonFurther information provided about the response. This field is returned only in certain cases.
statusSuccess indicator, returned as the string 'true'. Retained for backward compatibility.
referralcorner_urlsAn array containing the customer's Portal Sharing Pages for all campaigns they are enrolled in. Each entry is an object with campaignId (number) and url (string), and corresponds to a different campaign where the customer has been successfully enrolled. If the customer is not enrolled in any campaigns, this will return an empty array.

Sample Result

{"message":"Success","status":"true","referralcorner_urls":[{"campaignId":123,"url":"//refcandy.referralcandy.com/share/BW299X"}]}

Referrals Method GET

Overview

This method lets you query for referred purchases made over some period of time. This method is not available when the account is suspended and will return a HTTP 403 Forbidden status code.

Endpoint

GEThttps://my.referralcandy.com/api/v2.2/referrals.json

Input Parameters

FieldDescriptionRequired
period_fromUNIX timestamp of start of query period.yes
period_toUNIX timestamp of end of query period. Defaults to most recent timestamp.no
customer_emailAdvocate's email address. Return referred purchases made by advocate if set. Return all referred purchases if not set.no
pending_review_onlyWhether to only return referred purchases that are pending the review period (true/false). Defaults to false - this returns referred purchases regardless of review period status.no
timestampUNIX timestamp of API call.yes
accessIDAPI Access ID.yes
signatureCalculated signature.yes

Output Parameters

FieldDescription
referrals

Array of referred customers and referral timestamps.

FieldDescription
referral_emailEmail address of referred customer.
referral_timestampUNIX timestamp when referral purchase was made.
referring_emailEmail address of advocate who made the referral.
review_period_overWhether the review period for this referred purchase is over.
external_reference_idAn ID that can be used to track this referred purchase externally.
campaignIDCampaign ID that is associated to the referral
period_fromUNIX timestamp of start of query period.
period_toUNIX timestamp of end of query period of the results returned. This might not be the same as the period_to value requested since successful referrals can only be detected up till a couple of minutes before the current time.
messageA message indicating the outcome of the API call.
reasonFurther information provided about the response. This field is returned only in certain cases.

Sample Result

{"message":"Success","referrals":[{"referral_email":"referral1@example.com","referral_timestamp":1329738979,"referring_email":"customer@example.com","campaignID":321},{"referral_email":"referral2@example.com","referral_timestamp":1329738984,"referring_email":"customer@example.com","campaignID":123}],"period_from":1329738679,"period_to":1329739284}

Referral Method POST

Overview

This method lets you update the purchase status of a referred customer. By default, an email is sent out to the customer who made the referral to inform him/her that he/she is not eligible for a recent referral reward. This method is not available when the account is suspended and will return a HTTP 403 Forbidden status code.

Example

Bob makes a purchase at your store, referred by Amy. Bob returns his purchase. Make an 'Update Referral' API call, and set 'returned' to true. By default, Amy gets an email informing her that she is no longer eligible for the referral reward.

Endpoint

POSThttps://my.referralcandy.com/api/v2.2/referral.json

Input Parameters

FieldDescriptionRequired
customer_emailEmail address of customer who made the referred purchase.yes
notifyWhether to notify customer who referred customer specified above that the referral has been disregarded (true/false). Defaults to true.no
returnedWhether customer has returned his/her purchase (true/false). If 'returned' is set to true, the referral will be disregarded and rewards will not be paid out.yes
timestampUNIX timestamp of API call.yes
accessIDAPI Access ID.yes
signatureCalculated signature.yes

Output Parameters

FieldDescription
messageA message indicating the outcome of the API call.
reasonFurther information provided about the response. This field is returned only in certain cases.
customer_emailCustomer email address.
returnedWhether customer has returned his/her purchase.
campaignIdThe specific campaign ID the referral was associated with

Sample Result

{"message":"Success","customer_email":"customer@example.com","returned":true}

Referrer Method GET

Overview

This method lets you query for the referrer of a particular customer. This method is not available when the account is suspended and will return a HTTP 403 Forbidden status code.

Endpoint

GEThttps://my.referralcandy.com/api/v2.2/referrer.json

Input Parameters

FieldDescriptionRequired
customer_emailCustomer email address.yes
timestampUNIX timestamp of API call.yes
accessIDAPI Access ID.yes
signatureCalculated signature.yes

Output Parameters

FieldDescription
referrerEmail address of referring customer if one exists, null otherwise.
messageA message indicating the outcome of the API call.
reasonFurther information provided about the response. This field is returned only in certain cases.
campaignIdCampaign the referral belongs to

Sample Result

{"message":"Success","referrer":"referrer@example.com", "campaignId": 123}

Contacts Method GET

Overview

This method lets you query for contacts currently enrolled in your campaign. This method is not available when the account is suspended and will return a HTTP 403 Forbidden status code.

Example

Query with id = 50 and limit = 100 will return the 100 contacts invited to your first campaign after (and including) contact with id = 50.

Endpoint

GEThttps://my.referralcandy.com/api/v2.2/contacts.json

Input Parameters

FieldDescriptionRequired
idLowest id of contact returned by query. Defaults to 1.no
limitNumber of contacts to return. Defaults to 100. Capped at 100.no
emailWhen given, only the contact with this exact email address is returned.no
timestampUNIX timestamp of API call.yes
accessIDAPI Access ID.yes
signatureCalculated signature.yes
campaignIdFilter by campaign. Fallback to first campaign if not providedno

Output Parameters

FieldDescription
contacts

Array of contacts.

FieldDescription
idUnique identifier of contact.
first_nameFirst name of contact.
last_nameLast name of contact.
emailEmail address of contact.
purchase_madeWhether contact made a purchase at the store (true/false).
purchases

Array of purchases made by contact.

FieldDescription
purchased_atUNIX timestamp of purchase.
amountInvoice amount of purchase.
currencyISO 4217 currency code of the purchase.
unsubscribedWhether contact is unsubscribed (true/false).
total_countNumber of contacts returned in this response.
campaignIdID of the campaign the contacts were read from. Confirms which campaign's contacts are being returned when campaignId was omitted from the request.
limitNumber of contacts returned in this response. May be less than the requested limit if fewer contacts are available.
messageA message indicating the outcome of the API call.
reasonFurther information provided about the response. This field is returned only in certain cases.

Sample Result

{"message":"Success","total_count":2,"contacts":[{"id":800,"first_name":"Contact","last_name":"One","email":"contact1@example.com","purchase_made":true,"purchases":[{"purchased_at":1329738679,"amount":97.0,"currency":"USD"}],"unsubscribed":false},{"id":1250,"first_name":"Contact","last_name":"Two","email":"contact2@example.com","purchase_made":false,"purchases":[],"unsubscribed":false}],"campaignId":123,"limit":100}

Signup Method POST

Overview

This method lets you add a contact to the ReferralCandy system and attempts enrollment across all campaigns for the account. If the advocate is enrolled in the campaign, you can use this method to retrieve the advocate's referral link and Portal Sharing Page address for the campaign. The response includes per-campaign enrollment results. HTTP status is 200 if all campaigns enrolled successfully, 207 if partially enrolled, or 422 if no campaigns enrolled.

Endpoint

POSThttps://my.referralcandy.com/api/v2.2/signup.json

Input Parameters

FieldDescriptionRequired
first_nameAdvocate's first name.yes
last_nameAdvocate's last name.yes
emailAdvocate's email address.yes
timestampUNIX timestamp of API call.yes
accessIDAPI Access ID.yes
signatureCalculated signature.yes
campaignIdSets the primary campaign in the response. Fallback to first campaign if not provided. Enrollment is attempted across all campaigns regardless.no
segment_idID of a static segment to assign the contact to. Retrieve it from the dashboard. To enroll a contact in the given campaign, the segment must be set as the campaign’s target audience. Regardless of whether segment_id is present, the contact will be automatically added to any dynamic segment they fit the criteria for (e.g., LTV > 0).no

Output Parameters

FieldDescription
messageA message indicating the outcome of the API call.
reasonFurther information provided about the response. This field is returned only in certain cases.
referralcorner_urlURL of the advocate's Portal Sharing Page of the primary campaign enrollment. Empty/null if the primary campaign enrollment failed.
referral_linkURL of the advocate's unique referral link of the primary campaign enrollment. Empty/null if the primary campaign enrollment failed.
invite_codeThe latest invite code(AIC) of the advocate of the primary campaign enrollment. Empty/null if the primary campaign enrollment failed.
segmentSegment assignment details in json (only included when segment_id is provided). Contains: segmentId (number), assigned (boolean), and optionally reason (string) if assignment failed.
enrollmentsArray of enrollment results for each campaign. Each object contains: campaignId (number), enrolled (boolean), primary (boolean, indicates the primary campaign). When enrolled is true, includes referralcorner_url (string), referral_link (string or null), and invite_code (string or null). When enrolled is false, includes an error object with code (one of CAMPAIGN_PAUSED, CAMPAIGN_STOPPED, SEGMENT_MISMATCH, NOT_ENROLLED) and message (string).

Sample Result

{
  "message": "Success",
  "referralcorner_url": "http://refcandy.referralcandy.com/BW299X",
  "referral_link": "http://refcandy.refr.cc/ABCDEF",
  "invite_code": "BW299X",
  "enrollments": [
    {
      "campaignId": 101,
      "enrolled": true,
      "primary": true,
      "referralcorner_url": "http://refcandy.referralcandy.com/BW299X",
      "referral_link": "http://refcandy.refr.cc/ABCDEF",
      "invite_code": "BW299X"
    },
    {
      "campaignId": 102,
      "enrolled": true,
      "primary": false,
      "referralcorner_url": "http://refcandy.referralcandy.com/CX300Y",
      "referral_link": "http://refcandy.refr.cc/GHIJKL",
      "invite_code": "CX300Y"
    }
  ]
}

Invite Method POST

Overview

This method lets you send out a welcome email to a contact for your targeted campaign if the contact is enrolled in it. This method is not available when your targeted campaign is paused or stopped and will return a HTTP 403 Forbidden status code.

Endpoint

POSThttps://my.referralcandy.com/api/v2.2/invite.json

Input Parameters

FieldDescriptionRequired
emailContact's email address.yes
timestampUNIX timestamp of API call.yes
accessIDAPI Access ID.yes
signatureCalculated signature.yes
campaignIdSend invite to the campaign if the contact is enrolled to the campaign. No invite will be sent if contact is not enrolled to the campaign. Fallback to first campaign if not providedno

Output Parameters

FieldDescription
messageA message indicating the outcome of the API call.
reasonFurther information provided about the response. This field is returned only in certain cases.

Sample Result

{"message":"Success","invites":500}

Unsubscribed Method PUT

Overview

This method lets you unsubscribe and resubscribe a contact in your referral program. This method is not available when the campaign is stopped and will return a HTTP 403 Forbidden status code.

Endpoint

PUThttps://my.referralcandy.com/api/v2.2/unsubscribed.json

Input Parameters

FieldDescriptionRequired
emailContact's email address.yes
unsubscribedWhether to unsubscribe or resubscribe contact (true/false).yes
timestampUNIX timestamp of API call.yes
accessIDAPI Access ID.yes
signatureCalculated signature.yes

Output Parameters

FieldDescription
messageA message indicating the outcome of the API call.
reasonFurther information provided about the response. This field is returned only in certain cases.
emailCustomer email address.
unsubscribedWhether customer is unsubscribed.

Sample Result

{"message":"Success","email":"contact1@example.com","unsubscribed":true}

Get Rewards Method GET

Overview

This method lets you query for rewards which match some criteria. This method is not available when the account is suspended and will return a HTTP 403 Forbidden status code.

Endpoint

GEThttps://my.referralcandy.com/api/v2.2/rewards.json

Input Parameters

FieldDescriptionRequired
emailWhen given, the result only contains rewards from the advocate with this email address.no
since_idWhen given, the result starts from the next matching reward earned after the specified reward ID. Otherwise, the result starts with the first matching reward.no
statusWhen specified, the result contains rewards with the matching status. Otherwise, the result contains rewards matching all statuses. Accepted values are pending_fulfillment, delivered.no
typeWhen specified, the result contains rewards with the matching type. Otherwise, the result contains rewards matching all types. Accepted values are cash, coupon, custom, none.no
timestampUNIX timestamp of API call.yes
accessIDAPI Access ID.yes
signatureCalculated signature.yes
campaignIdcampaignIdno

Output Parameters

FieldDescription
messageA message indicating the outcome of the API call.
rewardsThe first 200 matching rewards.
since_idThe value specified in the request if available.
statusThe value specified in the request if available.
typeThe value specified in the request if available.
coupon_codeThe value specified in the request if available.
coupon_code_expiry_timestampThe value specified in the request if available.
coupon_code_dataThe value specified in the request if available.
coupon_usedIndicates whether this coupon has been used (true) or remains unused (false) in Shopify. Only available for Shopify merchants and only when Shopify can provide usage data.

Sample Result

{:message=>"Success", :rewards=>[{:advocate_email=>"john@example.com", :advocate_name=>"John Smith", :created_at=>1442584289, :description=>"20% discount", :id=>2, :status=>"delivered", :type=>"custom"}, {:advocate_email=>"alice@example.com", :advocate_name=>"Alice Bob", :created_at=>1442584426, :description=>"20% discount", :id=>3, :status=>"pending_fulfilment", :type=>"custom"}], :since_id=>1}

Reward Purchases Method GET

Overview

This method lets you query for the referred purchases that are associated with a reward. This method is not available when the account is suspended and will return a HTTP 403 Forbidden status code.

Endpoint

GEThttps://my.referralcandy.com/api/v2.2/reward_purchases.json

Input Parameters

FieldDescriptionRequired
reward_idThe ID of the reward.yes
timestampUNIX timestamp of API call.yes
accessIDAPI Access ID.yes
signatureCalculated signature.yes

Output Parameters

FieldDescription
messageA message indicating the outcome of the API call.
reasonFurther information provided about the response. This field is returned only in certain cases.
referred_purchasesThe list of the referred purchases that is associated with the reward.

Sample Result

{"message":"Success", "referred_purchases":[{"id":1, "external_reference_id":"ORDER_1", "purchaser_email":"john@example.com"},{"id":2, "external_reference_id":"ORDER_2", "purchaser_email":"alice@example.com"}]}

Post Rewards Method POST

Overview

This method lets you update a custom reward. This method is not available when the campaign is stopped and will return a HTTP 403 Forbidden status code.

Endpoint

POSThttps://my.referralcandy.com/api/v2.2/rewards.json

Input Parameters

FieldDescriptionRequired
idThe ID of the reward.yes
statusThe status of the reward. Accepted values are pending_fulfillment, delivered.yes
timestampUNIX timestamp of API call.yes
accessIDAPI Access ID.yes
signatureCalculated signature.yes

Output Parameters

FieldDescription
messageA message indicating the outcome of the API call if available.
reasonFurther details provided to help understand the response. This field is returned only in certain cases.
messagesA list of messages indicating the outcome of the API call if available.
rewardThe updated reward.

Sample Result

{:message=>"Success", :reward=>{:advocate_email=>"john@example.com", :advocate_name=>"John Smith", :created_at=>1442584289, :description=>"20% discount", :id=>3938282, :status=>"delivered", :type=>"custom"}}

API Clients

Open-source client libraries that handle signature generation for you:

Troubleshooting

Signature Calculation

A common mistake is that the same URI encoded API params for making a POST request are also used to compute the signature.

For example, if you had the following params:

{email: "abc@xyz.com", name: "john & jane"}

Your POST body would be URI encoded:

email=abc%40xyz.com&name=john+%26+jane

However, your MD5 should be computed with the literal string (not the URI encoded string):

MD5("...email=abc@xyz.comname=john & jane...")

Need a hand?

Your API Access ID and Secret Key live on your account settings page. For anything else, theSupport Centerand our support teamcan help.