NAV
PHP curl

Introduction

Welcome to the Yopify API! You can use our API to access Yopify API endpoints, which can get information on various events, settings in our database.

We have language bindings in curl and PHP! You can view code examples in the dark area to the right, and you can switch the programming language of the examples with the tabs in the top right.

Authentication

Generating API tokens

Pre-generated tokens can be used to authenticate use of the REST API endpoints. New tokens can be generated through the Settings.

alt tag

alt tag

See the attached screenshots:-

alt tag

alt tag

alt tag

Using API Tokens

To authorize, use this code:

use Yopify\Yo\Client;
        $client = new Client();

        $yoClient->authToken = 'YOUR-TOKEN-HERE'; // auth token can be found here: https://yopify.com/api/yo/settings#/api

        // OR

        $yoClient->setBasicAuth('me@mysite.com', 'secret'); // You can use basic auth also

        // Check autheticated user
        $isAuthenticated = $yoClient->ping(); // false if not authenticated, current timestamp if success
# With shell, you can just pass the correct header with each request
        curl "api_endpoint_here"
        -H "Authorization: yourapitoken"

        # You can use basic authentication

        curl "api_endpoint_here"
        -H "Authorization: Basic yourapitoken"

Make sure to replace yourapitoken/YOUR-TOKEN-HERE with your API token.

Yopify uses API keys to allow access to the API. You can register a new Yopify API token at your settings.

Yopify expects for the API token to be included in all API requests to the server.

The following methods can be used to authenticate the api request:-

GET https://yopify.com/api/yo/v1/events/1?api_token=yourapitoken

POST https://yopify.com/api/yo/v1/events/1?api_token=yourapitoken

api_token : yourapitoken

Authorization: yourapitoken

Events

Get All Events

$events = $client->getEvents(LIMIT, PAGE);

        // Check for success
        if (isset($events->meta)) {
        echo 'Current page: ', $events->meta->pagination->current_page, "\n";
        echo 'Total pages: ', $events->meta->pagination->total_pages, "\n";
        echo 'Page page: ', $events->meta->pagination->per_page, "\n";
        echo 'Total count: ', $events->meta->pagination->total, "\n";
        }
curl "https://yopify.com/api/yo/v1/events/<APPID>"
        -H "Authorization: yourapitoken"

Response:

{
        "data": [
        {
        "id": 1,
        "title": "event1",
        "first_name": "firstname",
        "last_name": "lastname",
        "city": "city",
        "province": "Unknown",
        "country": "country",
        "url": "",
        "image_url": "",
        "message_template": null,
        "status": 1,
        "message": null
        },
        {
        "id": 2,
        "title": "Title",
        "first_name": "Alex",
        "last_name": "Forbes",
        "city": "Sinagra",
        "province": "XXXX",
        "country": "Australia",
        "url": "",
        "image_url": "",
        "message_template": null,
        "status": 1,
        "message": null
        },
        ],
        "meta": {
        "success": true,
        "pagination": {
        "total": 10,
        "count": 10,
        "per_page": 10,
        "current_page": 1,
        "total_pages": 1,
        "links": []
        }
        }
        }

This endpoint retrieves all events.

HTTP Request

GET https://yopify.com/api/yo/v1/events/<APPID>?api_token=yourapitoken

We can also pass API token as query parameter like above

URL Parameters

Parameter Description
APPID The APPID from which events are to retrieve. By defult it is null, events will be retrieved from users default app

Query Parameters

Parameter Default Description
api_token null This is api token and is used to authenticate the request
sort null If available, it will be used to sort the events according to given column
limit 10 If it is passed then given number of records will be returned
page 0 If it is passed then records will be returned from the given page
order desc If it is passed then records will be sorted according to given order
search null If it is passed then records will be searched with given value

Get a Specific Event

$event = $yoClient->getEvent(EVENT_ID);
    
curl "https://yopify.com/api/yo/v1/events/<APPID>/<ID>"
        -H "Authorization: yourapitoken"

Response:

{
        "data": {
        "id": 1,
        "title": "event",
        "first_name": "firstname",
        "last_name": "lastname",
        "city": "city",
        "province": "province",
        "country": "country",
        "url": "https://google.com",
        "image_url": "https://www.google.co.in/logos/doodles/2016/jean-battens-107th-birthday-5170085972934656-hp.jpg",
        "message_template": "The most awaited [TITLE-WITH-LINK] is now available",
        "status": 1,
        "message": null
        },
        "meta": {
        "success": true
        }
        }

This endpoint retrieves a specific event.

HTTP Request

GET https://yopify.com/api/yo/v1/events/<APPID>/<ID>

URL Parameters

Parameter Description
ID The ID of the event to retrieve
APPID The APPID from which the event is to retrieve. By defult it is null, event will be retrieved from users default app

Create An Event

$event = new Yopify\Yo\YoEvent();
        $event->event_type_id = '1';
        $event->unique_id1 = '10';
        $event->unique_id2 = '1';
        $event->title = 'This awesome product';
        $event->first_name = 'Jon';
        $event->last_name = 'snow';
        $event->city = 'New York';
        $event->province = 'XXXX';
        $event->country = 'USA';
        $event->url = 'https://example.com';
        $event->message_template = '[FIRST-NAME] from [COUNTRY] just purchased [TITLE-WITH-LINK]';
        $YoEvent = $yoClient->createEvent($event);
curl -X POST https://yopify.com/api/yo/v1/events
        -H "Authorization: yourapitoken"
        -H "Content-Type: application/json"
        -d '{
        "title": "title",
        "first_name": "firstname",
        "last_name": "lastname",
        "city": "city",
        "province": "province",
        "country": "country",
        "url": "https://www.google.co.in",
        "image_url": "https://www.google.co.in/logos/doodles/2016/jean-battens-107th-birthday-5170085972934656-hp.jpg",
        "message_template": "[FIRST-NAME] by [TITLE-WITH-LINK]",
        "message": "firstname by <a href=\"https://www.google.co.in\">title</a>"
        }'

Response:

{
        "data": {
        "id": 30,
        "title": "title",
        "first_name": "firstname",
        "last_name": "lastname",
        "city": "city",
        "province": "province",
        "country": "country",
        "url": "https://www.google.co.in",
        "image_url": "https://www.google.co.in/logos/doodles/2016/jean-battens-107th-birthday-5170085972934656-hp.jpg",
        "message_template": "[FIRST-NAME] by [TITLE-WITH-LINK]",
        "status": "1",
        "message": "firstname by <a href=\"https://www.google.co.in\">title</a>"
        },
        "meta": {
        "success": true
        }
        }

This endpoint returns the saved event.

HTTP Request

POST https://yopify.com/api/yo/v1/events/<APPID>?api_token=yourapitoken

We can also pass API token as query parameter like above or in request body

Query Parameters

Parameter Default Description
api_token null This is api token and is used to authenticate the request

URL Parameters

Parameter Default Description
APPID null This is app id, if not passed then it will be saved in default app

Request Body Parameters

Parameter Required Data Type Description
app_token false integer If it passed then it can be used to autheticate the request
app_id false integer It is null if not passed
title true string This is title of the event. It is required and can contain maximum 250 characters
status false integer It is 1 by default
is_deleted false integer It is 0 by default
unique_id1 false string It is null by default but if it is passed then event already existed with it will be updated
unique_id2 false string It is null by default but if it is passed then event already existed with it will be updated
first_name true string It is first name of the event owner
last_name false string It is last name of the event owner
city true string It is city of the event owner
province true string It is province of the event owner
country true string It is country of the event owner
url false string It should be valid url.
image_url false string It should be valid url.
message_template false string It is null by default. It is notification message format to be used. You may modify by choosing preset labels/variables available.

Update An Event

$YoEvent = $yoClient->getEvent(EVENT_ID);

        if (isset($YoEvent->data)) {
        $YoEvent = $YoEvent->data;
        $YoEvent->province = "AAAA";

        $updatedEvent = $yoClient->updateEvent($YoEvent);
        }
curl -X PATCH https://yopify.com/api/yo/v1/events/<APPID>/<ID>
        -H "Authorization: yourapitoken"
        -H "Content-Type: application/json"
        -d '{

        "title": "title",
        "first_name": "firstname",
        "last_name": "lastname",
        "city": "city",
        "province": "province",
        "country": "country",
        "url": "https://www.google.co.in",
        "image_url": "https://yopify.com/api/yo/img/mono-logo.png",
        "message_template": "[FIRST-NAME] by [TITLE-WITH-LINK]",
        "message": "firstname by <a href=\"https://www.google.co.in\">title</a>"
        }'

Response:

{
        "data": {
        "id": 30,
        "title": "title",
        "first_name": "firstname",
        "last_name": "lastname",
        "city": "city",
        "province": "province",
        "country": "country",
        "url": "https://www.google.co.in",
        "image_url": "https://yopify.com/api/yo/img/mono-logo.png",
        "message_template": "[FIRST-NAME] by [TITLE-WITH-LINK]",
        "status": "1",
        "message": "firstname by <a href=\"https://www.google.co.in\">title</a>"
        },
        "meta": {
        "success": true
        }
        }

This endpoint returns the updated event.

HTTP Request

PATCH https://yopify.com/api/yo/v1/events/<APPID>/<ID>?api_token=yourapitoken

We can also pass API token as query parameter like above or in request body

Query Parameters

Parameter Default Description
api_token null This is api token and is used to authenticate the request

URL Parameters

Parameter Description
APPID This is app id, if not passed then it will be saved in default app
ID This is id of the event to be updated

Request Body Parameters

Parameter Required Data Type Description
app_token false integer If it passed then it can be used to autheticate the request
app_id false integer It is null if not passed
title true string This is title of the event. It is required and can contain maximum 250 characters
status false integer It is 1 by default
is_deleted false integer It is 0 by default
unique_id1 false string It is null by default but if it is passed then event already existed with it will be updated
unique_id2 false string It is null by default but if it is passed then event already existed with it will be updated
first_name true string It is first name of the event owner
last_name false string It is last name of the event owner
city true string It is city of the event owner
province true string It is province of the event owner
country true string It is country of the event owner
url false string It should be valid url.
image_url false string It should be valid url.
message_template false string It is null by default. It is notification message format to be used. You may modify by choosing preset labels/variables available.

Delete an event

$deletedEvent = $yoClient->deleteEvent(EVENT-ID);
curl -X DELETE "https://yopify.com/api/yo/v1/events/<APPID>/<ID>"
        -H "Authorization: yourapitoken"

Response:

{
        "data": {
        "id": 1,
        "title": "event title",
        "first_name": "firstname",
        "last_name": "lastname",
        "city": "city",
        "province": "province",
        "country": "country",
        "url": "https://valid_url",
        "image_url": "https:\\/\\/www.google.co.in\\/logos\\/doodles\\/2016\\/jean-battens-107th-birthday-5170085972934656-hp.jpg",
        "message_template": "The most awaited [TITLE-WITH-LINK] is now available",
        "status": 1,
        "message": null
        },
        "meta": {
        "success": true,
        "message": "Event Deleted"
        }
        }

This endpoint deletes the event with given id.

HTTP Request

DELETE https://yopify.com/api/yo/v1/events/<APPID>/<ID>

URL Parameters

Parameter Description
ID The ID of the event to retrieve
APPID The APPID from which the event is to retrieve. By defult it is null, event will be retrieved from users default app

Settings

Update Settings

curl -X PATCH https://yopify.com/api/yo/v1/app-settings/<APPID>/<ID>
        -H "Authorization: yourapitoken"
        -H "Content-Type: application/json"
        -d '{
        "api_token": "yourapitoken",
        "closable": 1,
        "url_color": "#23454545",
        }'

Response:

{
        "success": true,
        "data": {
        "disable_on_mobile": "true",
        "loop": "false",
        "closable": "true",
        "timestamp_language": "en",
        "randomize_timestamp": "false",
        "initial_delay": "10",
        "display_hold": "5",
        "display_interval": "30",
        "randomize_interval": "true",
        "random_interval_from": "77",
        "random_interval_to": "77",
        "url_color": "#454545",
        "url_font_weight": "false",
        "background_color": "",
        "message_color": "#000000",
        "message_font_weight": "false",
        "timeago_color": "#000000",
        "timeago_font_weight": "false",
        "events_threshold": "864000",
        "timeago_limit": "172800",
        "events_per_page": "100",
        "message_template": "Someone from [CITY], [COUNTRY] recently pur[TIME-AGO]chased [PRODUCT-WITH-LINK] [TIME-AGO]",
        "fallback_city": "hisar",
        "theme_style_id": "1",
        "position": "bottom-left",
        "animation_type": "fade-bl",
        "Utm": "1",
        "utm_source": "yo",
        "utm_medium": "notification",
        "enabled": "true"
        }
        }

This endpoint returns the updated settings.

HTTP Request

PATCH https://yopify.com/api/yo/v1/app-settings/<APPID>

URL Parameters

Parameter Description
APPID This is app id, if not passed then these will be updated in default app

Request Body Parameters

Parameter Data Type Default Description
app_token integer null If it passed then it can be used to autheticate the request
app_id integer null It is null if not passed
timestamp_language string en Choose language in which timestamp to localize. It can be one of these 'en,nl,de,es,et'.
events_per_page integer 100 It should be integer. Maximum no. of events notifications you want to show on a page. (If your store has less events, then the events can be repeated)
position string bottom-left It can be one of these bottom-left,top-left,bottom-right,top-right. It is Notifications position on browsers
random_interval_from integer 10 Delay will be calculated between the selected range. It is required if randomize_interval option is true
random_interval_to integer 59 Display notifications with random interval. It is required if randomize_interval option is true
enabled boolean true It is used to indicate whether settings are enabled or not
enable_on_mobile boolean true Disable to hide the notifications over mobile devices.
loop boolean true When Yo runs out of recent events to display, it will loop all the recent events that are set in your duration settings below.
closable boolean false This will add an 'x' to your notification so visitors can close the notifications from displaying to them. They won't be able to see the notifications anymore until they've cleared their cache.
initial_delay integer 10 When a person first visits your site, Yo will wait this long before displaying the first notification.
display_hold integer 5 Each notification will be visible for this duration.
display_interval integer 30 It will show next and so forth notifications after selected interval. (If you have selected random delay, then this setting will be ignored)
randomize_interval boolean false Display notifications with random interval.
url_color string (empty string ) It is Custom Color for [TITLE-WITH-LINK] and it is an option for Choosing the color that you'd like your product link to display as
randomize_timestamp boolean false This option is for Random Timestamp
url_font_weight boolean 0 Normal font or Bold font for [TITLE-WITH-LINK]
background_color string (empty string ) Customize the color of the background for the notification. To revert to the default color, clear the color code so the box is empty.
message_color string (empty string ) Customize the color of your message. To revert to the default color, clear the color code so the box is empty.
message_font_weight string (empty string) Normal font or Bold font for Message except [TITLE-WITH-LINK]
timeago_color string (empty string) Customize the color of the time stamp. To revert to the default color, clear the color code so the box is empty.
timeago_font_weight string (empty string) Normal font or Bold font for [TIME-AGO]
events_threshold string 864000 Display all events that are within this time period. Any events that are older than the 'Timeago Duration' will still display but won't have the time stamp. This helps your store looking lively and busy even if you don't have many daily events.
timeago_limit string 172800 Only add the 'time ago' timestamp on events within this duration. For example, only display the timestamp on events within the last 1 hour.
message_template string Someone from [CITY], [COUNTRY] recently purchased [TITLE-WITH-LINK] [TIME-AGO] Notification message format. You may modify by choosing preset labels/variables available.
fallback_city string (empty string ) It will be displayed if you've included [CITY] in your message and value of [CITY] in your event is empty
theme_style_id integer 3 Select existing theme for notifications or you may customize by choosing custom.
animation_type string slide-bl-b Select the animation type you want to display notifications with
Utm string 1 UTM option of settings
utm_source string yo It is UTM source option of the settings
utm_medium string notification It is UTM Medium option of the settings

Users

Verify User

curl  https://yopify.com/api/yo/v1/ping/<APPID>/<ID>
        -H "Authorization: yourapitoken"

Response:

{
        "status": true,
        "time": 1475932271
        }

This endpoint returns status true with timestamp if user is valid.

HTTP Request

GET https://yopify.com/api/yo/v1/ping/<APPID>

URL Parameters

Parameter Description
APPID This is app id, if not passed then user will be returned from default app

Others

Storing Lemonstand Store Orders

curl  -X POST https://yopify.com/api/yo/v1/ls/orders/<APPID>
        -H "Authorization: yourapitoken"

Response:

This endpoint is used to store lemonstand orders as events.

HTTP Request

POST https://yopify.com/api/yo/v1/ls/orders/<APPID>

URL Parameters

Parameter Description
APPID This is app id, if not passed then these will be updated in default app

Errors

The Yopify API uses the following error codes:

Error Code Meaning
400 Bad Request -- There is something wrong with your request
401 Unauthorized -- Your API token is wrong
403 Forbidden -- The event requested is hidden for administrators only or you are not a valid user
404 Not Found -- The specified event/setting could not be found
405 405 Method Not Allowed - If requested method is not allowded on the resource
500 Internal Server Error -- You may have done something wrong in your request or we had a problem with our server. Try again later.