Setting up the APIs

Smart Router has APIs for web and mobile app clients and also for servers. Each of these APIs performs a separate task but what they all have in common is a main ProcessOut object that you use to access the API features. The sections below show you the “boilerplate” setup code that you will use repeatedly as you develop a project.

Contents

Public and private keys for a project

Throughout our example code, you will see strings like

proj_gAO1Uu0ysZJvDuUpOGPkUBeE3pGalk3x

and

key_sandbox_mah31RDFqcDxmaS7MvhDbJfDJvjtsFTB

passed as parameters during initialization. The first string is an example of a project public key that you use to identify your project to Smart Router (you can think of it as the project’s “username”). This is required for both client and server code. The second string is a corresponding project private key that you use only on the server to authenticate it to Smart Router (you can think of it as the project’s “password”).

To obtain the public key for your project, go to Dashboard › Developer API › API setup and copy the text from the Production public key textbox. Create a corresponding private key using the Create new private key button on the same page.

Enabling the sandbox

To test your code in the sandbox, you must use public and private keys that are slightly different from the production keys. The sandbox public key is the same as the production key but with the prefix test- added (so proj_gAO1Uu0ysZ... becomes test-proj_gAO1Uu0ysZ...). The private key for production won’t work at all in the sandbox and so you must generate a separate key for testing. To add a new sandbox private key, go to the Dashboard and enable the Sandbox mode switch at the bottom of the navigation bar. If you now go to Dashboard › Developer API › API setup as before, you will see a list of sandbox private keys. Clicking the Create new private key button will now create the sandbox key you need for testing.

Web client

Start by loading the processout.js library in your web page.

<script src="https://js.processout.com/processout.js"></script>

Note: for security purposes, it is very important that you serve this file only from our content delivery network (CDN) as shown above. You should not keep a local copy of this file on your server.

The processout.js library has no dependencies on jQuery or any other library, so the <script> tag above is all you need to start using Smart Router.

Once this is loaded, you must create a ProcessOut object to access the API using your project public key:

var client = new ProcessOut.ProcessOut(
    "proj_gAO1Uu0ysZJvDuUpOGPkUBeE3pGalk3x"
);

iOS app client

You can get the Smart Router SDK for iOS (v8.0 and above) from CocoaPods by adding

pod 'ProcessOut'

to your Podfile and then running

pod install

from the Terminal. When the pod is installed, configure the SDK in your AppDelegate with the following Swift code:

ProcessOut.Setup(projectId: "proj_gAO1Uu0ysZJvDuUpOGPkUBeE3pGalk3x")

Android app client

You can get the Smart Router SDK for Android (v14 and above) from JitPack. Add the following line to your build file under the repositories section:

maven { url 'https://jitpack.io' }

You must also add a dependency to your build.gradle file:

compile 'com.github.processout:processout-android:2.+'

You can then initialize the SDK in your Java code:

final ProcessOut client = new ProcessOut(
    this, 
    "proj_gAO1Uu0ysZJvDuUpOGPkUBeE3pGalk3x"
);

Server

The server API supports 5 languages ( Node.js, Python, Ruby, PHP, and Go ) and a REST API interface that you can access using a tool such as Curl. For the language APIs, you must first install the appropriate library package from the command line (the Curl REST API doesn’t need this step):

# No setup required for Curl
npm install processout
pip install processout
gem install processout
composer require processout/processout-php
go get gopkg.in/processout.v4  // godoc: https://godoc.org/gopkg.in/processout.v4

When the library package is installed, you can instantiate a ProcessOut object using the project’s public and private keys:

curl -X GET https://api.processout.com/ \
    -u test-proj_gAO1Uu0ysZJvDuUpOGPkUBeE3pGalk3x:key_sandbox_mah31RDFqcDxmaS7MvhDbJfDJvjtsFTB
var ProcessOut = require("processout");
var client = new ProcessOut(
    "test-proj_gAO1Uu0ysZJvDuUpOGPkUBeE3pGalk3x",
    "key_sandbox_mah31RDFqcDxmaS7MvhDbJfDJvjtsFTB");

import processout
client = processout.ProcessOut(
    "test-proj_gAO1Uu0ysZJvDuUpOGPkUBeE3pGalk3x", 
    "key_sandbox_mah31RDFqcDxmaS7MvhDbJfDJvjtsFTB")

require "processout"
client = ProcessOut::Client.new(
    "test-proj_gAO1Uu0ysZJvDuUpOGPkUBeE3pGalk3x", 
    "key_sandbox_mah31RDFqcDxmaS7MvhDbJfDJvjtsFTB")

<?php
$client = new \ProcessOut\ProcessOut(
    "test-proj_gAO1Uu0ysZJvDuUpOGPkUBeE3pGalk3x", 
    "key_sandbox_mah31RDFqcDxmaS7MvhDbJfDJvjtsFTB");

import "github.com/processout/processout-go"

var client = processout.New(
    "test-proj_gAO1Uu0ysZJvDuUpOGPkUBeE3pGalk3x", 
    "key_sandbox_mah31RDFqcDxmaS7MvhDbJfDJvjtsFTB",
)

Note that the Curl/REST interface does not remember your keys between calls, so you must pass them each time via the -u/--user option in the format shown.