All Collections
Frequently Asked Questions
General
Can I use the API to fetch PURLs for my customers? I want to include PURLs in emails to customers and elsewhere on my site.
Can I use the API to fetch PURLs for my customers? I want to include PURLs in emails to customers and elsewhere on my site.
Samantha avatar
Written by Samantha
Updated over a week ago

For information regarding API access, please see here

For more information regarding the API in general, please visit our REST API docs.

You can use our REST API to create or retrieve a PURL using both customer ids and email addresses.

For each PURL that you want, make a POST request to https://api.friendbuy.com/v1/referral_codes, sending the customer id or email you want to use in addition to the id of the widget you want these PURLs to be associated with. For more details on the formatting, see http://www.friendbuy.com/rest-api-reference/#referral-codes.

If we do not already have a PURL associated with that widget and customer id or email pair, then we will create one. If one already exists, we will retrieve it. In either case, the response to the API call will include the purl in a property called "trackable_link". Just grab that property and insert it into an email to that customer or display it somewhere on your site for them to see.

For example, lets say you want to send all of your customers an email with their PURL in it. For each customer you would make the following Curl call:

curl -XPOST \
  -H "Content-Type: application/json" \
  -d '{"email": customer_email,
         "campaign": {"id": campaign_id}}' \
  https://API_USERNAME:API_PASSWORD@api.friendbuy.com/v1/referral_codes

where customer_email is the email address of the customer and campaign_id is the id of the campaign you are using to generate the PURLs.

The response to each of those calls will look like:

{
    "referral_code": "reN",
    "type": "personal_url",
    "campaign": {
        "id": 2544,
        "name": "Fall sale",
        "published": true,
        "referral_incentive": {
            "type": "shopper_fixed_revenue",
            "value": "10.00"
        },
        "created_at": "2014-07-25T13:59:52.328016-07:00"
    },
    "customer": {
        "id": "C9997",
        "email": null
    },
    "trackable_link": "http://fbuy.me/reN"
}

Simply get the "trackable_link" from the response and insert it into the email and you are ready to move onto the next customer!

Did this answer your question?