NAV
shell php

Introduction

To make things work in Traken, we need you to make an integration to populate your screens with real data, and to show your users a proper index.

That integration is just RESTful service where our platform will connect to retrieve data. It will take you just a few hours of work.

Starting with Traken

It’s very important for you to read our getting started guide.

You can start using Traken in a few steps:

Traken App

Don’t forget to download Traken App and create a new Traken App account.

We suggest you to create the first Traken App account with the same email address of your Traken platform account. You’ll be able to see some sample services we’ve implemented there. The rest of your users will see only your implemented service (and they’ll need a Traken App account too).

Traken requests

This is a sample of Traken index retrieval to your RESTful service for user miguel@trakenapp.com

curl -X GET https://traken-api.my-sample-store.com/index?email=miguel@trakenapp.com \
     -u 'YOUR_API_KEY':none

Your endpoint should return JSON structured like this:

[
  {
    "title": "Last orders",
    "tplId": 25,
    "link": "https://traken-api.my-sample-store.com/orders",
    "link_id": "orders"
  },
  {
    "title": "Store balance",
    "tplId": 33,
    "link": "https://traken-api.my-sample-store.com/balance",
    "link_id": "balance"
  },
  {
    "title": "Best sellers",
    "tplId": 36,
    "link": "https://traken-api.my-sample-store.com/bestsellers",
    "link_id": "bestsellers"
  },  
  {
    "title": "Server status",
    "tplId": 30,
    "link": "https://traken-api.my-sample-store.com/server",
    "link_id": "server"
  }
]

This JSON Code should validate correctly against our JSON Index Schema

All the requests in Traken go through our platform. This is necessary to make things work in Traken.

We know you could be concerned about your data safety, but you should not. We act only as a proxy between you and your users. We take privacy very seriously, so Traken will never store or use any information you send to your final users.

Traken communication flow

Traken will make two kind of requests to your endpoint:

Integrate with Traken

Index request

This is a sample of Traken index retrieval to your RESTful service for user miguel@trakenapp.com

curl -X GET https://myapi.my-stripe-middleware.com/index?email=miguel@trakenapp.com \
     -u 'YOUR_API_KEY':none
<?php
/**
 * Returns the index 
 */
function getIndex() {
  $Stripe_sample_index = Array(Array('title'   => 'Balance',
                                     'tplId'   => 51,
                                     'link'    => 'https://myapi.my-stripe-middleware.com/balance',
                                     'link_id' => 'balance',
                                     'default' => true),
                               Array('title'   => 'Last payments',
                                     'tplId'   => 52,
                                     'link'    => 'https://myapi.my-stripe-middleware.com/payments',
                                     'link_id' => 'payments')
                              );
  return json_encode($Stripe_sample_index);
}

?>

Your endpoint should returns JSON structured like this:

[
  {
    "title": "Balance",
    "tplId": 51,
    "link": "https://traken-api.my-stripe-middleware.com/balance",
    "link_id": "balance",
    "default": true
  },
  {
    "title": "Last payments",
    "tplId": 52,
    "link": "https://traken-api.my-stripe-middleware.com/payments",
    "link_id": "payments"
  }
]

This is the index you will show to your users in Traken App and the main entry point for us.

GET https://traken-api.my-sample-company.com/index?email=:email

URL Parameters

Parameter Required Value Description
email yes string The email of the user who has made the request.

Index response format

The index is a JSON array of objects. The maximum number of items is 6.

Element Required Value Description
title yes string Title of the menu item. We will show it in Traken App.
tplId yes number ID of the Traken template to represent the information in Traken App.
link yes string URL on your side where we will make the data request.
link_id yes string Unique ID of the link. Only letters and numbers allowed.
default no boolean Set if to true if this is the default element. If many or none, only the first will be taken.

Resources:

Data request

Sample request from Traken to your endpoint

GET curl -X GET https://traken-api.my-sample-company.com/payments?email=:email \
     -u 'YOUR_API_KEY':none

Sample response from your endpoint

{
    "widget1": {
        "title": "Fuerteventura",
        "subtitle": "The paradise",
        "image": "https://farm3.staticflickr.com/2882/10161207834_91f5b814d4_k.jpg"
    },
    "widget2": [
        {
            "label": "Purchases January",
            "value": 456
        },
        {
            "label": "Purchases Febraury",
            "value": 678
        },
        {
            "label": "Purchases March",
            "value": 551
        }
    ],
    "widget3": [
        {
            "title": "CPU",
            "value": 70
        },
        {
            "title": "Storage",
            "value": 129,
            "total": 700,
            "unit": "GB"
        },
        {
            "title": "Bandwidth",
            "value": 34
        }
    ]
}

This is the request made to populate a screen with real data. You have to create as many data requests as items in your index.

Every screen is unique. You can find its specific documentation in our backend. Just go to “Templates” and click on the screen you need. You’ll find all the necessary documentation to handle the specific request for the template (general information, examples, response format and JSON Schema). Make sure your response validate against its JSON Schema. Use JSON Schema Validator and JSON Lint Validator

Here, we can show the generic structure of a data request and a sample code on the right.

URL Parameters

Parameter Required Value Description
email yes string The email of the user who has made the request.

Data response format

The response is a JSON object of objects and/or arrays. There will be as many as widgets in your template.

Element Required Value Description
widgetN yes object/array Widget data.
N = Widget number, as indicated in the backend documentation. (widget1, widget2, widget3…)

Sample format:

{ "widget1": { ... }, "widget2": [ ... ], "widget3": [ ... ] }

Resources:

List last 10 invoices for user “miguel@trakenapp.com”

GET curl -X GET https://traken-api.my-sample-company.com/invoices?email=miguel@trakenapp.com \
     -u 'YOUR_API_KEY':none

Show invoice #345123 to user “miguel@trakenapp.com”

GET curl -X GET https://traken-api.my-sample-company.com/invoices?email=miguel@trakenapp.com&link_id=invoice.345123 \
     -u 'YOUR_API_KEY':none

The items of the “Data List” widget can be linked to another view using the “link” property. If we detect this property in any item of this widget, it will be linkable in Traken App.

When you use links, you have to provide us a template ID and a Link ID

Parameter Required Value Description
tpl_id yes number The ID of the template to be used in the linked view.
link_id yes string The necesary information you need to retrieve the linked information.

To retrieve the link data, we will call again the same URL, but with the parameter link_id.

Main URL: GET https://traken-api.my-sample-company.com/invoices?email=:email

Link URL: GET https://traken-api.my-sample-company.com/invoices?email=:email&link_id=:link_id

Debugging

Traken is really easy to work with, but shit happens and you’ll need as much information as possible to debug your integration.

First of all, we strongly recommend you to test all your services against the JSON Schema validators ( JSON Schema Validator and JSON Lint Validator ) and check it with Postman too before testing against Traken App or going to production. This will save you a lot of headaches.

If everything is OK when testing with Postman and data validation, you shouldn’t have problems. But this is not “Alice in Wonderland”, so you can find some minor problems in the last stage of the integration. You’ll detect this errors while trying to access to your service in Traken App. A message like “DataReq-*” will appear if there is a problem or maybe a blank screen (timeout). If so, go to your backend Error Log section to have more information and check it again with Postman.

If the problem persists or you need help, send us a support request.

Troubleshooting

Data validation

If the data returned doesn’t validate against your template schema or if the JSON is malformed, Traken App will show a data validation error to your users in Traken App. An error DataReq-* will be shown.

DataReq error in App

DataReq error will appear in Traken App when trying to request information against a non valid URL, when the service is unavailable or when was imposible for us to validate your data against the template schema.

How can you solve it?

Once you have solved the problem, clear Traken App cache (Settings -> Clear cache), close the app and open it again.

It this doesn’t solve the problem, send us a support request

A red “error” text can appear next to your service name in Traken App. This means that there was an error trying to request your user index.

This can happens for several reasons:

How can you solve it?

Once you have solved the problem, clear Traken App cache (Settings -> Clear cache), close the app and open it again.

It this doesn’t solve the problem, send us a support request

Timeout / Host not reachable

Error shown in Traken App if we don’t get the data in an acceptable response time. You can get also a blank screen in Traken App if this happens.

Authentication

We will make an HTTP Basic Auth to your RESTful endpoint, using the Customer API Key you provided by Traken in your backend. You are responsible for the validation.

Index cache

Traken cache your user index for 24h (we have index cache copies for every user). Due to the way Traken communicates with your endpoint, we can’t notice if you makes changes to your user index. If you make any changes, you have to wait 24hours for the cache to refresh or ask users to clear cache under app settings. In a future you will be able to handle cache settings.

Reference error while validating

When trying to validate against our JSON Schemas using JSON Schema Validator you can get an error about references not defined. This is due to the incapacity of this service to properly resolve references in JSON Schemas. In this case, use JSON Lint Validator instead.

Anyway, we recomend to use JSON Schema Validator as it gives you more information for debugging.

Tests

You should test your services before implementing in Traken. You can use cURL or Postman to test your or our APIs. Remember that the information you return Traken has to validate against your template schemas or your users will get a validation error message. You can use JSON Schema Validator and JSON Lint Validator under development to tests your services before publishing.

Once you have tested your services, you can add test users to check everything is ok. Then, add your production users.

Support request

If you find and unknown problem or you are not able to solve it, we’ll be glad to help you. Just send us a support request.

Sample integration

  ,ad8888ba,  88 88            88         
 d8"'    `"8b 88 ""            88         
d8'           88               88         
88            88 88  ,adPPYba, 88   ,d8   
88            88 88 a8"     "" 88 ,a8"    
Y8,           88 88 8b         8888[      
 Y8a.    .a8P 88 88 "8a,   ,aa 88`"Yba,   
  `"Y8888Y"'  88 88  `"Ybbd8"' 88   `Y8a  



88888888ba  88        88 88888888ba   
88      "8b 88        88 88      "8b  
88      ,8P 88        88 88      ,8P  
88aaaaaa8P' 88aaaaaaaa88 88aaaaaa8P'  
88""""""'   88""""""""88 88""""""'    
88          88        88 88           
88          88        88 88           
88          88        88 88           

<?php
// We use composer to load Stripe and Slim
require 'vendor/autoload.php';

// Initializate Slim
$app = new \Slim\Slim();

// Set headers to JSON
$app->response->headers->set('Content-Type', 'application/json');

/**
 *  HTTP Basic Auth function
**/
function auth($app) {
  // The API Key that Traken will use to access to your API
  $service_api_key = '$2y$10$azolhkLKJBH986)(&9kljLKh)(6kjlñlgGVrvT30PvZUx%$%%5HPGedEy3y';

  // We check the user send against our stored API Key
  if (!isset($_SERVER['PHP_AUTH_USER']) || trim($_SERVER['PHP_AUTH_USER']) == '' || trim($_SERVER['PHP_AUTH_USER']) != $service_api_key) {
            $response = [
                "code" => 'Not-Authorized',
                "message" => 'Not authorized.',
                "description" => 'You are not authorized to access to this API.',
                "status" => 0
            ]; 
      $app->response->status(401);
            echo json_encode($response);
            return false;
    } else return true; 
};

/**
 *  Main URL that we have to set in Traken Backend. 
 *  It represents our app user menu
**/
$app->get('/index', function () use ($app) {
  // Auth
  if(auth($app)) {
    $links = Array(
      Array(
        'title' =>  'Balance',
        'tplId' =>  51,
        'link'  =>  'https://trakenapi.mycompany.com/balance',
        'link_id' =>  'balance',
        'default' => true
        ),
      Array(
        'title' =>  'Payments',
        'tplId' =>  52,
        'link'  =>  'https://trakenapi.mycompany.com/payments',
        'link_id' =>  'payments'
        ),
      );

    echo json_encode($links);
  }
});


/**
* Stripe balance
**/
$app->get('/balance', function () use ($app, $links) {
  // Auth
  if(auth($app)) {
    // Set Stripe API Key
    Stripe\Stripe::setApiKey('STRIPE_ACCESS_TOKEN');

    // Get balance information
    $balance = Stripe\Balance::retrieve();

    // Get last 4 charges
    $charges = Stripe\Charge::all(array("limit" => 4, 'include' => ["total_count"]));

    // Prepare total pending and total available information
    $totalAv = 0;
    $totalPe = 0;

    foreach($balance->available as $av)
      $totalAv += $av->amount;

    foreach($balance->pending as $pe)
      $totalPe += $pe->amount;    

    // Prepare some values we'll need to represent
    $totalBalance = ($totalPe + $totalAv)/100;
    $percPend = $totalPe / $totalBalance;

    // We prepare an array with the last payments to be shown in the last widget.
    // We want to show the status of the payment, amount, credit card information and some custom icons.
    // The array has the same structure as the widget3 (3x2 Data List), and will be then encoded to JSON.
    $trkCharges = array();
    foreach($charges->data as $charge) {
      if($charge->status == 'succeeded') $paymentStatus = 'paid';
      if($charge->status == 'failed') $paymentStatus = 'failed';
      if($charge->refunded == true) $paymentStatus = 'refunded';

      switch($paymentStatus) {
        case 'paid':
          $title = 'Payment charged';
          $icon = 'ion-checkmark';
          $color = '#5945fe';
          break;
        case 'refunded':
          $title = 'Payment refunded';
          $icon = 'ion-arrow-graph-down-left';
          $color = '#158fc0';
          break;
        case 'failed':
          $title = 'Payment failed';
          $icon = 'ion-alert-circled';
          $color = '#fca436';
          break;
        // Unknown status
        default:
          $title = 'Payment (unknown status)';
          $icon = 'ion-minus';
          $color = '#ababab';         
          break;                    
      }

      $subtitle = $charge->source->brand . ' *** ' . $charge->source->last4;
      $amount = $charge->amount / 100;

      $trkCharges[] = array(  'title' => $title,
                  'subtitle' => $subtitle,
                  'right_text_big' => "$amount",
                  'right_text_small' => $charge->currency,
                  'icon' =>   array(
                    'classname' => $icon,
                    'color' => $color
                  )
              );
    }

    // Now, we transform the information to Traken screen JSON data representation

    // Widget1 (3x2 Text Hero). Current and pending balance.
    $w1 = array('title' => '$' . $totalBalance,
          'subtitle' => 'Current balance ($' . $totalAv / 100 .')',
          'image' => 'https://images.unsplash.com/photo-1432672301844-a3619c197980?ixlib=rb-0.3.5&q=80&fm=jpg&crop=entropy&w=1024&s=aea5ca87f0c2793803c1737e60fec1a7'
      );

    // Widget2 (3x1 Individual Chart Radial). Pending balance (chart + data)
    $w2 = array('title' => 'Pending balance',
          'subtitle' => '$' . $totalPe / 100,
          'value' => floor($percPend)
      );

    // Widget3 (3x2 Data List). Last four payments
    $w3 = $trkCharges;

    // We merge, encode and return the information.
    echo json_encode(array('widget1' => $w1, 'widget2' => $w2, 'widget3' => $w3));
  }
});

/**
* Last payments registered in Stripe
**/
$app->get('/payments', function () use ($app, $links) {
  // Auth
  if(auth($app)) {
    Stripe\Stripe::setApiKey('STRIPE_ACCESS_TOKEN');
    $charges = Stripe\Charge::all(array("limit" => 10, 'include' => ["total_count"]));

    // We prepare an array with the last payments to be shown in the last widget.
    // We want to show the status of the payment, amount, credit card information and some custom icons.
    // The array has the same structure as the widget3 (3x2 Data List), and will be then encoded to JSON.
    $trkCharges = array();

    foreach($charges->data as $charge) {
      if($charge->status == 'succeeded') $paymentStatus = 'paid';
      if($charge->status == 'failed') $paymentStatus = 'failed';
      if($charge->refunded == true) $paymentStatus = 'refunded';

      switch($paymentStatus) {
        case 'paid':
          $title = 'Payment charged';
          $icon = 'ion-checkmark';
          $color = '#5945fe';
          break;
        case 'refunded':
          $title = 'Payment refunded';
          $icon = 'ion-arrow-graph-down-left';
          $color = '#158fc0';
          break;
        case 'failed':
          $title = 'Payment failed';
          $icon = 'ion-alert-circled';
          $color = '#fca436';
          break;
        // Unknown status
        default:
          $title = 'Payment (unknown status)';
          $icon = 'ion-minus';
          $color = '#ababab';         
          break;                    
      }

      $subtitle = $charge->source->brand . ' *** ' . $charge->source->last4;
      $amount = $charge->amount / 100;

      $trkCharges[] = array(  'title' => $title,
                  'subtitle' => $subtitle,
                  'right_text_big' => "$amount",
                  'right_text_small' => $charge->currency,
                  'icon' =>   array(
                    'classname' => $icon,
                    'color' => $color
                  )
              );
    }

    // We merge, encode and return the information.
    echo json_encode(array('widget1' => $trkCharges));    
  }
});


// Run Slim
$app->run();
?>

There is nothing better than taking a look at a real example to understand how things work.

For this example, we are creating a service that connects with Stripe and allows us to see the payments we’ve received in our Stripe account.

We have decided to create two screens:

This will be also our users menu.

You can access to the backend and create the two screens. We have used the next widgets: - Balance screen: 3x2 Text Hero + 3x1 Individual Radial Chart + 3x2 Data List - Payments screen: One 3x5 data list widget.

They will look like this images:

Stripe balance screen Stripe payments screen

Note that the screens will show you sample data when you create it, but you can customize a lot of aspects of the screens.

For example, the Data List widgets can have customized icon and color, and you can replace all the texts. You can find information about the widget structure in the “Response format” tab under your template screen (backend). Also, the example and JSON Schema can bring you a lot of information.

Let see, for example, the parameters of our “Payments screen” and the example code.

Payments data format

As the screen is composed only of one widget, we have one unique data representation. This is automatically named “widget1” by Traken. We need to know what is the JSON representation of that widget.

As we can see, it’s a “3x5 Data List” widget. This widget is an array (1..10 elements) of objects with this representation

Member Type Description
title string Title of the row
subtitle string Subtitle of the row.
right_text_big string Big text in the right side.
right_text_small string Small text in the right side, under the big text. (optional).
icon object Icon representation:
classname (string): Class name of the icon. We use ionicons.
color (string): Hex color code. i.e. #FFF000

Sample JSON representation of the screen

{
    "widget1": [
        {
            "title": "Invoice #32213",
            "subtitle": "Web design services",
            "right_text_big": "$3,125.99",
            "right_text_small": "PAID",
            "icon": {
                "classname": "ion-ios-checkmark",
                "color": "#33CC33"
            }
        },
        {
            "title": "Invoice #32214",
            "subtitle": "Social Media Marketing",
            "right_text_big": "$1,242.34",
            "right_text_small": "UNPAID",
            "icon": {
                "classname": "ion-ios-close",
                "color": "#FF0000"
            }
        }
    ]
}

In the right side (shell tab), you can see a JSON sample representation of this screen data. You can see this example also in the “example” tab of the template link from the backend.

At this moment, we have defined the index of our service and our two screens.

Now, we have to create the data source in our endpoint and tell Traken how to access.

We will use:

The first thing we do is make the auth function. This function will validate any incoming request to be sure that only Traken will access to your services. We will call this function later.

Then, we prepare the index, according to the Traken Index Schema. In PHP, we set an array that will then encode to JSON. We have set two URLs in our index for payments and balance. We have to indicate also a link_id and the ID of the template to use.

After we have created our index, we create two new routes: /balance and /payments.

In each one, we take care and the validation, retrieve the data from Stripe API and prepare it according to the structure of our two screens. Then, we encode the data to JSON and return it.

Congratulations, we’ve created our first endpoint!!! :)

Now, configure Traken how to access your endpoint and retrieve data. We have to access the backend and set as main URL the index URL of our service: https://trakenapi.mycompany.com/index (replace the URL by yours) and our endpoint API Key. After that, Traken knows how to access to your endpoint.

We have just to make the final step, add the emails of the users that will have access to your service using Traken App. Just go to “user management” in Traken backend and add the emails of the active Traken App users… Et voilà!

You have survived to the creation of a Traken service.

The API

API Overview

We provide you some API methods to interact with Traken. With these methods you can keep your users in sync with Traken and send push notifications to them. You’ll need to use a Traken API Key, you can get it in your customer backend (Service configuration -> Traken API Key)

Traken API Endpoint

https://api.trakenapp.com

Authentication

curl -X POST https://api.trakenapp.com/notification \
     -u 'YOUR_API_KEY':none
     ...

Requests should be authenticated using HTTP Basic Auth. You have to provide Traken API Key as username and an empty password.

Users

We provide API methods for your user management. After you make your first batch load of users in the backend, you can keep them in sync using the API.

Add user

Request

curl -X POST https://api.trakenapp.com/user \
     -u 'YOUR_API_KEY':none \
     -H 'Accept: application/json' \
     -d '{ "email": "miguel@trakenapp.com" }'

Body

{
    "email": "miguel@trakenapp.com"
}
  <?php
  $trakenService = 'https://api.trakenapp.com/user';

  $requestBody = array(
    'email' => 'miguel@trakenapp.com',
  );

  $trakenAPIkey = 'YOUR_TRAKEN_API_KEY';

  $req = curl_init();
  curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($req, CURLOPT_POST, true );
  curl_setopt($req, CURLOPT_POSTFIELDS, $requestBody);
  curl_setopt($req, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($req, CURLOPT_USERPWD, $trakenAPIkey .':'); 
  curl_setopt($req, CURLOPT_URL, $trakenService);

  $respCode = curl_getinfo($req, CURLINFO_HTTP_CODE);
  $resp = json_decode(curl_exec($req), true);

  curl_close($req);
  ?>

Sample response

{
  "code": "user_added_inactive",
  "message": "User not registered in our App.",
  "description": "The user is not yet registered in Traken. We added it to a temporary table to be created once the user is registered in our system.",
  "data": null,
  "status": 21
}

Add a user authorizated to use your application. The user will be identified by an email address.

POST https://api.trakenapp.com/user

Parameter Value Description
email string Email of the user

Responses

Code Status Description
EmailNotSpecified-USRADD 0 Email Not specified.
EmailNotValid-USRADD 0 The string provided is not a valid email address.
DB-ErrorProccessingRequest-* 0 Traken internal error.
already_existed 10 You’ve already added this email address. The user is active (has downloaded Traken App).
already_existed 20 You’ve already added this email address. The user is not active (has not downloaded Traken App).
user_added 11 The user has been added and is an active Traken App user.
user_added_inactive 22  The user has been added to your account but has not downloaded Traken App yet. He/she will be moved as an active user as soon as signs up.
MaxUsersReached-USRADD 0 You have reached the maxium users allowed by your plan.

Get user information

Request

curl -X GET https://api.trakenapp.com/user/:email \
     -u 'YOUR_API_KEY':none \
     -H 'Accept: application/json' 
  <?php
  $trakenService = 'https://api.trakenapp.com/user/%s';
  $userEmail = 'miguel@trakenapp.com';
  $trakenAPIkey = 'YOUR_TRAKEN_API_KEY';

  $req = curl_init();
  curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($req, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($req, CURLOPT_USERPWD, $trakenAPIkey .':');
  curl_setopt($req, CURLOPT_URL, sprintf($trakenService, $userEmail));

  $respCode = curl_getinfo($req, CURLINFO_HTTP_CODE);   
  $resp = json_decode(curl_exec($req), true);

  curl_close($req);
  ?>

Sample response

{
  "code": "active_user",
  "message": "User found and active.",
  "description": "We have found the requested user and it is active in our service.",
  "data": null,
  "status": 11
}

Get user information. This is useful to know if the user has been added and the status (is an app user or not).

GET https://api.trakenapp.com/user/:email

Parameter Value Description
email string Email of the user

Responses

Code Status Description
EmailNotSpecified-USRGET 0 Email Not specified.
DB-ErrorProccessingRequest-* 0 Traken internal error.
not_found 0 He hasn’t found users with these email address associated to your account.
active_user 11 The user is an active Traken App user.
inactive_user 21  The user has not downloaded Traken App yet or has signed up with a different email account.

Delete user

Request

curl -X DEL https://api.trakenapp.com/user \
     -u 'YOUR_API_KEY':none \
     -H 'Accept: application/json' 

Body

{
    "email": "miguel@trakenapp.com"
}
<?php
  $trakenService = 'https://api.trakenapp.com/user';

  $requestBody = array(
    'email' => 'miguel@trakenapp.com',
  );

  $trakenAPIkey = 'YOUR_TRAKEN_API_KEY';

  $req = curl_init();
  curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($req, CURLOPT_CUSTOMREQUEST, "DELETE");
  curl_setopt($req, CURLOPT_POSTFIELDS, $requestBody);
  curl_setopt($req, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($req, CURLOPT_USERPWD, $trakenAPIkey .':'); 
  curl_setopt($req, CURLOPT_URL, $trakenService);

  $respCode = curl_getinfo($req, CURLINFO_HTTP_CODE);
  $resp = json_decode(curl_exec($req), true);

  curl_close($req);
?>

Sample response

{
  "code": "deleted",
  "message": "User deleted succesfully.",
  "description": "The user has been removed from your service and will not have access anymore unless you add it again.",
  "data": null,
  "status": 1
}

Delete the user

DEL https://api.trakenapp.com/user

Parameter Value Description
email string Email of the user

Responses

Code Status Description
EmailNotSpecified-USRDEL 0 Email Not specified.
DB-ErrorProccessingRequest-* 0 Traken internal error.
not_found 0 He haven’t found users with these email address associated to your account.
deleted 1 The user has been deleted from your account.

Notifications

Traken allows you to easily send push notifications to your users in a single POST Request. You just have to indicate the user email, the message, and the link ID of the menu item vinculated with the notification.

Request

curl -X POST https://api.trakenapp.com/notification \
     -u 'YOUR_API_KEY':none \
     -H 'Accept: application/json' \
     -d '{ "email": "miguel@trakenapp.com", "message": "You have a new customer!", "link_id": "customers" }'

Body

{
    "email": "miguel@trakenapp.com",
    "message": "You have a new customer!",
    "link_id": "customers"
}
  <?php
  $trakenService = 'https://api.trakenapp.com/notification';

  $requestBody = array(
    'email'   => 'miguel@trakenapp.com',
    'message' => 'You have a new customer!',
    'link_id' => 'customers'    
  );

  $trakenAPIkey = 'YOUR_TRAKEN_API_KEY';

  $req = curl_init();
  curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($req, CURLOPT_POST, true );
  curl_setopt($req, CURLOPT_POSTFIELDS, $requestBody);
  curl_setopt($req, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($req, CURLOPT_USERPWD, $trakenAPIkey .':'); 
  curl_setopt($req, CURLOPT_URL, $trakenService);

  $respCode = curl_getinfo($req, CURLINFO_HTTP_CODE);
  $resp = json_decode(curl_exec($req), true);

  curl_close($req);
  ?>

Sample response

{
  "code": "notification_sent",
  "message": "Notification sent.",
  "description": "The notification has been succesfully sent to the user.",
  "status": 1
}

Send push notification

POST https://api.trakenapp.com/notification

Parameter Value Description
email string Email of the user
message string The message
link_id string The menu item ID vinculated to the notification. When the user receives the notification, he/she can clicks on it and will be redirected to the associated screen to see the new information.

Responses

Code Status Description
ParamNoneSpecified-NotificationSend 0 You have not specified any parameter
ParamSomeNotSpecified-NotificationSend 0 You have not specified certain parameter/s.
NotAuthorized 0 New accounts are sandboxed. You have to contact us to allow you to send push notifications. Go to the backend for instructions or just use our contact form.
DB-ErrorProccessingRequest-* 0 Traken internal error.
user_not_found 0 We haven’t found any user associated to your account with the provided email.
blocked 0 The user has blocked your service.
spam 0  The user has flagged you as a spammer.
notification_sent_not-logged 1 The user is not logged, so the notification has been delayed to be delivered to the user as soon as he signs in back if possible.
notification_error 0 Traken internal error.
notification_sent 1 The notification has been sent.
MaxPushReached 0 You have reached the maximum push notifications allowed by your plan.

Requests

Body

Request and response are both JSON.

Traken response format

Sample response from Traken

{
  "code": "not_found",
  "message": "User not found.",
  "description": "We have not found any user associated to the provided email.",
  "data": null,
  "status": 0
}

Traken responses consists in a JSON object which consists of the next members:

Element Value Description
code string Unique string which will indicate the code of the response.
message string Short description of the response.
description string Long description of the response.
data array/null If needed, the data of the request will be included here.
status number Numeric code of the response.
0: Always indicates an error.
1: Success.
Other code numbers could be returned. These additional codes are specified for each API method.

Errors

Wrong API Key

You have indicated a wrong API Key, or not API key at all. Take care to indicate the Traken API Key. This is the API Key provided by Traken for you to interact with our API. Traken API Key is different from Customer API Key (which is the one used to authenticate Traken Requests in your side).

Not using SSL

You have not made an SSL request.

Account disabled or not activated

You can’t use our API until you activate your account.

Account is sandboxed

When you create your account, it will be sandboxed until we verify it. You can’t send push notifications until we activate your account.

Method not allowed for your plan

Maybe your plan doesn’t allow some methods (like push notifications if it’s a free or demo plan).

Glossary