Getting started overview
Integrating Sift involves a sequence of steps to configure your environment and begin sending data for fraud analysis. The primary goal is to establish secure communication between your application and the Sift API, allowing Sift to receive event data, analyze it, and return fraud scores or decisions. This initial setup focuses on account creation, API key generation, and executing a basic event submission.
Sift processes various event types, such as $transaction, $login, and $create_account, which inform its machine learning models. Accurate and consistent event data submission is foundational for effective fraud detection. The first request typically involves sending a simple event to confirm connectivity and credential validity.
Here is a quick reference table outlining the essential steps for getting started with Sift:
| Step | What to Do | Where to Find Information |
|---|---|---|
| 1. Account Creation | Sign up for a Sift account. | Sift Homepage |
| 2. API Key Retrieval | Locate your API key in the Sift Console. | Sift API Basics documentation |
| 3. SDK/API Client Setup | Install a Sift SDK or configure an HTTP client. | Sift API Reference |
| 4. First Event Submission | Send a basic event (e.g., $transaction) to the Sift API. |
Sift Transaction Event documentation |
| 5. Response Verification | Check the API response for success and initial scores. | Sift API Response Guide |
Create an account and get keys
To begin using Sift, you must first establish an account. Sift offers custom enterprise pricing, and initial access typically involves contacting their sales team to discuss specific use cases and volume requirements. Once an agreement is in place, you will gain access to the Sift Console, your central hub for configuration, data analysis, and API key management.
After logging into the Sift Console, locating your API key is the next critical step. The API key serves as your authentication credential for all API requests. Sift typically provides both a Production API Key and a Sandbox API Key. It is crucial to use the appropriate key for your development and production environments to prevent unintended data operations or billing issues.
To retrieve your API key:
- Log in to your Sift Console.
- Navigate to the API Keys section, often found under 'Settings' or 'Integrations'.
- Copy your API key. Sift's documentation on Sift API Basics provides specific instructions for locating and managing these keys. Keep your API key secure, treating it like a password, and avoid hardcoding it directly into client-side code or public repositories.
Sift recommends using environment variables or a secure configuration management system to store and access your API keys, particularly in server-side applications, to minimize exposure. For instance, in a Node.js environment, you might access it via process.env.SIFT_API_KEY after setting the environment variable.
Your first request
After obtaining your API key, the next step is to make your first API call to Sift. This validates your setup and ensures that your application can communicate with Sift's servers. Sift's API is RESTful, accepting JSON payloads and returning JSON responses. You can interact with it directly via HTTP requests or use one of Sift's official SDKs.
Sift provides SDKs for several popular server-side languages, including Python, Node.js, Java, PHP, and Ruby. Using an SDK can simplify the process by handling HTTP requests, JSON serialization, and error handling. For this example, we'll demonstrate a basic transaction event using the Node.js SDK, which is one of the primary language examples Sift highlights.
Using the Node.js SDK
First, install the Sift Node.js SDK:
npm install @siftscience/sift-sdk
Next, create a JavaScript file (e.g., send_sift_event.js) and add the following code. This example sends a $transaction event, a common starting point for e-commerce fraud detection:
const Sift = require("@siftscience/sift-sdk");
// Replace with your actual API key
const sift = new Sift(process.env.SIFT_API_KEY);
const userId = "billy_jones_301";
const transactionId = "ORDER-238497";
const eventProperties = {
$user_id: userId,
$session_id: "gigtuk " + Math.random().toString(36).substring(7),
$transaction_id: transactionId,
$merchant_id: "23490",
$currency_code: "USD",
$amount: 1050000, // $1050.00 in minor units
$billing_address: {
$name: "Bill Jones",
$phone: "1-415-555-6040",
$address_1: "2100 Main Street",
$address_2: "Apt 3B",
$city: "New York",
$region: "NY",
$country: "US",
$zipcode: "10001"
},
$payment_methods: [
{
$payment_type: "credit_card",
$card_bin: "411111",
$card_last4: "1111"
}
],
$items: [
{
$product_title: "Microwave Oven",
$item_id: "abcd123",
$price: 1000000, // $1000.00
$quantity: 1
},
{
$product_title: "LED Light",
$item_id: "efgh456",
$price: 50000, // $50.00
$quantity: 1
}
]
};
sift.track("$transaction", eventProperties, (err, response) => {
if (err) {
console.error("Error sending Sift event:", err);
} else {
console.log("Sift event sent successfully:", response.body);
if (response.body.score) {
console.log("Fraud score:", response.body.score);
}
}
});
Before running, set your API key as an environment variable:
export SIFT_API_KEY="YOUR_SIFT_API_KEY"
node send_sift_event.js
A successful response will typically include a score object, indicating Sift's assessment. For detailed information on event properties and expected responses, refer to the Sift API reference documentation.
Direct HTTP Request (Curl Example)
If you prefer to interact directly with the API without an SDK, you can use a tool like curl. This demonstrates the underlying HTTP POST request to Sift's events endpoint.
curl -X POST \
https://api.sift.com/v205/events \
-H 'Content-Type: application/json' \
-d '{
"$api_key": "YOUR_SIFT_API_KEY",
"$type": "$transaction",
"$user_id": "billy_jones_301",
"$session_id": "gigtuk_example",
"$transaction_id": "ORDER-238497",
"$merchant_id": "23490",
"$currency_code": "USD",
"$amount": 1050000,
"$billing_address": {
"$name": "Bill Jones",
"$phone": "1-415-555-6040",
"$address_1": "2100 Main Street",
"$address_2": "Apt 3B",
"$city": "New York",
"$region": "NY",
"$country": "US",
"$zipcode": "10001"
},
"$payment_methods": [
{
"$payment_type": "credit_card",
"$card_bin": "411111",
"$card_last4": "1111"
}
],
"$items": [
{
"$product_title": "Microwave Oven",
"$item_id": "abcd123",
"$price": 1000000,
"$quantity": 1
}
]
}'
Remember to replace YOUR_SIFT_API_KEY with your actual Sift API key. The $api_key field is required when sending events directly via the API, whereas SDKs typically handle this through initialization.
Common next steps
Once you have successfully sent your first event to Sift, consider these common next steps to further integrate and optimize your fraud prevention strategy:
- Implement additional event types: Sift's effectiveness increases with the breadth of data it receives. Integrate other relevant event types beyond transactions, such as
$create_account,$login,$add_item_to_cart, and$update_account. Each event type provides valuable signals for Sift's machine learning models. Consult the Sift event API documentation for a comprehensive list and required properties. - Integrate Decision API: While the Events API sends data to Sift for scoring, the Decision API allows you to retrieve real-time fraud decisions and apply them directly within your application workflow. This is crucial for automating actions like blocking suspicious transactions or flagging high-risk user accounts. The Sift Decisions API documentation provides details on how to query for decision outcomes.
- Set up Webhooks: For asynchronous fraud decisions or to receive notifications about manually reviewed cases, configure webhooks. Sift can send real-time alerts to a specified endpoint in your system when a score changes or a decision is made. This enables your application to react to fraud signals without constantly polling Sift's API. Twilio's webhook security guide offers general best practices for securing webhook endpoints, which are applicable when setting up Sift webhooks.
- Utilize the Sift Console: Explore the Sift Console to review fraud scores, investigate individual events, and understand the reasons behind specific decisions. The console provides tools for case management, rule configuration, and performance monitoring, allowing you to fine-tune your fraud detection logic.
- Define Custom Rules: Beyond Sift's machine learning models, you can define custom rules within the Sift Console to enforce specific business logic or address unique fraud patterns relevant to your operations. These rules can trigger actions based on combinations of event properties and Sift scores.
Troubleshooting the first call
Encountering issues during your initial API call is common. Here are some troubleshooting steps:
- Check API Key: Ensure your API key is correct and being passed securely. A common error is using a Sandbox API key in a production environment or vice-versa, or having a typo in the key itself. Verify it matches the key displayed in your Sift Console.
- Verify Endpoint: Confirm you are sending requests to the correct Sift API endpoint (e.g.,
https://api.sift.com/v205/events). Using an incorrect URL will result in connection errors. - Inspect Request Payload: The JSON payload sent to Sift must be well-formed and include all required fields for the specific event type. Refer to the Sift API reference for the exact schema of each event. Missing required fields or incorrect data types will lead to validation errors.
- Review HTTP Status Codes: Pay attention to the HTTP status code returned by Sift.
200 OK: Indicates success.400 Bad Request: Often means there's an issue with your request payload (e.g., malformed JSON, missing required fields). The response body will usually contain specific error messages.401 Unauthorized: Typically indicates an invalid or missing API key.403 Forbidden: Your API key may lack the necessary permissions for the requested action.5xx Server Error: Suggests an issue on Sift's side. If these persist, consult Sift support.- Check Network Connectivity: Ensure your server or development environment has outbound network access to
api.sift.com. Firewall rules or proxy settings can sometimes block these connections. - Consult Sift Documentation and Support: The Sift documentation portal is the primary resource for detailed error codes and troubleshooting guides. If issues persist, contact Sift support directly with your request details and any error messages received.