Introduction to ViralSweep's API

Welcome to the ViralSweep API. You can use our API to access endpoints to add and retrieve data within your ViralSweep account.

To access the API, you need the ViralSweep Premium Plan or higher. View pricing →

We've provided usage examples written in PHP and cURL. These examples should be enough to demonstrate how to make calls to the same endpoints from different programming languages. All API endpoints return a JSON response.

We recommend using Postman for testing API endpoints.

Authentication

ViralSweep requires an API key to access all endpoints. Register a new API key in your Account Settings.

Include your API key in every request as a request header:

x-api-key: YOUR-API-KEY-HERE

Replace YOUR-API-KEY-HERE with your personal API key from Account Settings.
PHP / cURL
<?php
$process = curl_init();
curl_setopt($process, CURLOPT_URL,
  'https://app.viralsweep.com/api/brands');
curl_setopt($process, CURLOPT_HTTPHEADER, array(
  'content-type: application/json',
  'x-api-key: YOUR-API-KEY-HERE'
));
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($process);
curl_close($process);
?>

Brands

GET Get All Brands

This endpoint retrieves all brands in your ViralSweep account.

HTTP Request

GET https://app.viralsweep.com/api/brands

Return Values

Returns an array of all brands. Each item contains:

ParameterDescription
idUnique identifier of the brand
nameName of the brand
Don't forget to include the x-api-key header in your request!
PHP / cURL
<?php
$process = curl_init();
curl_setopt($process, CURLOPT_URL,
  'https://app.viralsweep.com/api/brands');
curl_setopt($process, CURLOPT_HTTPHEADER, array(
  'content-type: application/json',
  'x-api-key: YOUR-API-KEY-HERE'
));
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($process);
curl_close($process);
print_r(json_decode($return));
?>
Response
{
  "brands": [
    {
      "id": 1,
      "name": "Company1"
    },
    {
      "id": 2,
      "name": "Company2"
    }
  ]
}

Promotions

GET Get All Promotions

This endpoint retrieves all promotions for a brand.

HTTP Request

GET https://app.viralsweep.com/api/promotions/<BRAND_ID>

URL Parameters

ParameterDescription
<BRAND_ID>Unique identifier of the brand
allSet to true to fetch archived promotions
activeSet to true to fetch only active promotions

Return Values

ParameterDescription
idUnique identifier of the promotion
titleTitle of the promotion
typeType of promotion (e.g. sweeps, photo)
start_tsUNIX timestamp of the promotion start date
end_tsUNIX timestamp of the promotion end date
timezoneThe time zone the promotion is set to run in
Don't forget to include the x-api-key header in your request!
PHP / cURL
<?php
$process = curl_init();
curl_setopt($process, CURLOPT_URL,
  'https://app.viralsweep.com/api/promotions/<BRAND_ID>');
curl_setopt($process, CURLOPT_HTTPHEADER, array(
  'content-type: application/json',
  'x-api-key: YOUR-API-KEY-HERE'
));
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($process);
curl_close($process);
print_r(json_decode($return));
?>
Response
{
  "promotions": [
    {
      "id": 1,
      "title": "Promotion 1 Title",
      "type": "sweeps",
      "start_ts": "123456789",
      "end_ts": "123456789",
      "timezone": "(GMT-05:00) Eastern Time"
    }
  ]
}

Entries

GET Get All Entries

This endpoint retrieves all entries for a promotion.

HTTP Request

GET https://app.viralsweep.com/api/entries/<PROMOTION_ID>

URL Parameters

ParameterDescription
<PROMOTION_ID>Unique identifier of the promotion
pageNumeric value of which page to query
countNumber of results per page (defaults to 25)
queryWildcard search term to query email addresses

Return Values

ParameterDescription
bonusArray of data about bonus actions completed
emailEmail address of the entrant
entered_tsUNIX timestamp of when the user entered
entries_totalTotal entries a user has earned
fieldsArray of data user submitted via entry form
ipIP address
locationGeo-location based on IP address lookup
referrals_countTotal referrals a user has earned
short_urlURL user can share to gain referrals
login_linkURL you can send users to auto login
rankReturned when searching a specific email on waitlist promotions
entries_usedReturned on instant win promotions
referred_byEmail address of referring entrant
Don't forget to include the x-api-key header in your request!
PHP / cURL
<?php
$process = curl_init();
curl_setopt($process, CURLOPT_URL,
  'https://app.viralsweep.com/api/entries/<PROMOTION_ID>');
curl_setopt($process, CURLOPT_HTTPHEADER, array(
  'content-type: application/json',
  'x-api-key: YOUR-API-KEY-HERE'
));
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($process);
curl_close($process);
print_r(json_decode($return));
?>
Response
{
  "entries": [
    {
      "email": "testuser@viralsweep.com",
      "entered_ts": "1561016558",
      "location": "Cheshire, CT",
      "ip": "64.12.33.27",
      "entries_total": "24",
      "referrals_count": "2",
      "short_url": "https://swee.ps/XyTRls",
      "fields": {
        "first_name": "John",
        "last_name": "Smith"
      },
      "bonus": [{
        "title": "Entering",
        "entries": "5",
        "time": "123456789"
      }]
    }
  ]
}

POST Add Entry

This endpoint adds a new entry to a promotion.

HTTP Request

POST https://app.viralsweep.com/api/entries/<PROMOTION_ID>

Parameters

ParameterDescription
<PROMOTION_ID>Unique identifier of the promotion
email *Email address of the entrant (required)
first_nameEntrant's first name
last_nameEntrant's last name
phoneEntrant's phone number
addressEntrant's address
address2Entrant's address line 2
cityEntrant's city
stateEntrant's state
zipEntrant's postal code
countryEntrant's country
birthday_monthEntrant's birth month
birthday_dayEntrant's birth day
birthday_yearEntrant's birth year
referrer_emailEmail of the referring entrant (must already exist in the promotion)

Custom Fields

For custom fields, add them to your entry form first, then use the browser inspector to find the field's id attribute and use that as the parameter key.

Don't forget to include the x-api-key header in your request!

Return Values

ParameterDescription
successOnly returned if entry was accepted
urlReferral share URL for the new entrant
errorOnly returned if there was an error
messageExplanation of the result
PHP / cURL
<?php
$post_fields = array(
  'email'      => 'jdoe@gmail.com',
  'first_name' => 'John',
  'last_name'  => 'Doe'
);

$process = curl_init();
curl_setopt($process, CURLOPT_URL,
  'https://app.viralsweep.com/api/entries/<PROMOTION_ID>');
curl_setopt($process, CURLOPT_HTTPHEADER, array(
  'content-type: application/json',
  'x-api-key: YOUR-API-KEY-HERE'
));
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_POSTFIELDS,
  json_encode($post_fields));
curl_setopt($process, CURLOPT_CUSTOMREQUEST, 'POST');
$return = curl_exec($process);
curl_close($process);
print_r(json_decode($return));
?>
Success Response
{
  "success": 1,
  "url": "https://swee.ps/fdgdS"
}
Error Response
{
  "error": 1,
  "message": "bad_email"
}

POST Add Entry Points

This endpoint adds (or subtracts) points for an entrant.

HTTP Request

POST https://app.viralsweep.com/api/points/<PROMOTION_ID>

Parameters

ParameterDescription
<PROMOTION_ID>Unique identifier of the promotion
email *Email address of the entrant (required)
pointsPoints to add (use a negative value to subtract)
descriptionExplanation of the points added or subtracted
Don't forget to include the x-api-key header in your request!

Return Values

ParameterDescription
successOnly returned if points were updated
errorOnly returned if there was an error
messageExplanation of the result
PHP / cURL
<?php
$post_fields = array(
  'email'       => 'jdoe@gmail.com',
  'points'      => '5',
  'description' => 'For visiting our page'
);

$process = curl_init();
curl_setopt($process, CURLOPT_URL,
  'https://app.viralsweep.com/api/points/<PROMOTION_ID>');
curl_setopt($process, CURLOPT_HTTPHEADER, array(
  'content-type: application/json',
  'x-api-key: YOUR-API-KEY-HERE'
));
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_POSTFIELDS,
  json_encode($post_fields));
curl_setopt($process, CURLOPT_CUSTOMREQUEST, 'POST');
$return = curl_exec($process);
curl_close($process);
print_r(json_decode($return));
?>
Response
{
  "success": 1,
  "message": "Points Updated"
}

POST Entry Validation

This endpoint validates or invalidates entries by email address.

HTTP Request

POST https://app.viralsweep.com/api/validate/<PROMOTION_ID>

Parameters

ParameterDescription
<PROMOTION_ID>Unique identifier of the promotion
email *Email address(es) of the entrants. Accepts a comma-separated list for bulk updates.
validationAllowed values: valid, invalid, accept, unaccept
Don't forget to include the x-api-key header in your request!

Return Values

ParameterDescription
successOnly returned if validation was updated
errorOnly returned if there was an error
messageExplanation of the result
PHP / cURL
<?php
$post_fields = array(
  'email'      => 'jdoe@gmail.com',
  'validation' => 'valid'
);

$process = curl_init();
curl_setopt($process, CURLOPT_URL,
  'https://app.viralsweep.com/api/validate/<PROMOTION_ID>');
curl_setopt($process, CURLOPT_HTTPHEADER, array(
  'content-type: application/json',
  'x-api-key: YOUR-API-KEY-HERE'
));
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_POSTFIELDS,
  json_encode($post_fields));
curl_setopt($process, CURLOPT_CUSTOMREQUEST, 'POST');
$return = curl_exec($process);
curl_close($process);
print_r(json_decode($return));
?>
Response
{
  "success": 1,
  "message": "Validation Updated"
}

Winners

GET Get All Winners

This endpoint retrieves all winners for a promotion.

HTTP Request

GET https://app.viralsweep.com/api/winners/<PROMOTION_ID>

URL Parameters

ParameterDescription
<PROMOTION_ID>Unique identifier of the promotion
begin_tsUNIX timestamp to filter winners from this date
end_tsUNIX timestamp to filter winners up to this date
Don't forget to include the x-api-key header in your request!

Return Values

ParameterDescription
emailEmail of the winner
ipIP address of the winner
entered_tsUNIX timestamp of the winner's entry date
created_tsUNIX timestamp of when they won
prizeTitle of prize, if available
codeWinning entry code, if available
PHP / cURL
<?php
$process = curl_init();
curl_setopt($process, CURLOPT_URL,
  'https://app.viralsweep.com/api/winners/<PROMOTION_ID>');
curl_setopt($process, CURLOPT_HTTPHEADER, array(
  'content-type: application/json',
  'x-api-key: YOUR-API-KEY-HERE'
));
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$return = curl_exec($process);
curl_close($process);
print_r(json_decode($return));
?>
Response
{
  "winners": [
    {
      "email": "winner@domain.com",
      "ip": "123.123.123.123",
      "entered_ts": "123456789",
      "created_ts": "123456789",
      "prize": "Prize Title Here"
    }
  ]
}

Errors

Our API is in beta. We will expand on this section as our API endpoints require it.

The ViralSweep API will return a JSON response if there is an error authenticating.

Return Values

ParameterDescription
errorExplanation of the error
Error Response
{
  "error": "Could not authenticate"
}