Getting Started - .NET

What you'll learn: How to record data and get your first analysis results via the API
Duration: 30 minutes

Table Of Contents

warning icon

To complete this guide you'll need an identity configured for your account with a valid Facebook access token. This will have been setup by your account manager or a member of our sales team. Use your account API USERNAME and a valid IDENTITY API KEY to complete this example.

Before You Start

Before you start this guide, if you haven't already done so take a look at our PYLON 101 page to learn the key concepts of the platform.

You work with Pylon by:

  • Recording data into an index
  • Submitting analysis queries to the index to receive analysis results

This guide will help you create a program including one method for starting a recording, and another for performing analysis. When you come to build your application you'll no doubt want to separate the two flows in a similar way.

Installing the Client Library

The .NET library is available as a NuGet package on here.

Create a new Command Line Application in Visual Studio 2012 or above.

Install the client library using the Package Manager Console:


Recording Data

With your project started and the library now installed, now you can start writing your application.

Open Program.cs in your new application. Firstly include the following namespaces at the top of the file:

using DataSift;
using DataSift.Rest;
using Newtonsoft.Json;

Next replace the Main method with this code laying out the structure of the simple program and creating a client object that will access the API for you.

You'll need to insert your API username and key here!

// References we'll need to keep
private static DataSiftClient _client;
static void Main(string[] args)
    // Create a new DataSift client
    _client = new DataSiftClient("ACCOUNT_API_USERNAME", "IDENTITY_APIKEY");
    // Our program
    var recordingId = StartRecording();

    // Wait for key press before ending example
    Console.WriteLine("-- Press any key to exit --");

static string StartRecording() {}

static void Analyze(string recordingId) {}

Compiling a Filter

To record data you'll need to compile a filter.

Compiling a filter will give you a hash that you can use when setting up a recording.

Add the following code to the StartRecording method.

// Compile a filter to receive a hash
var csdl = @"( fb.content contains_any ""wedding,engaged,engagement,marriage"" 
                    or in ""Wedding,Marriage"" ) 
                    OR ( fb.parent.content contains_any ""wedding,engaged,engagement,marriage"" 
                    or in ""Wedding,Marriage"" )";

var compiled = _client.Pylon.Compile(csdl);
var hash = compiled.Data.hash;

Console.WriteLine("Hash: " + hash);

Creating a Recording

Now that you have a hash for your filter, you can use this to start recording data to your index. Starting the recording will give you an id. When you perform analysis you'll use this id to reference the recording.

Add the following code to the StartRecording method.

// Start the recording, 
string recordingId = null;
var start = _client.Pylon.Start(hash, "Pylon Test Filter");
recordingId =;

Console.WriteLine("Recording running!");
Console.WriteLine("Recording ID: " + recordingId);

// Return ID for analysis later
return recordingId;

Start Recording

As you're working with live data, you'll need to let the data start filling up the index before we can perform any useful analysis.

Kick off recording by running your application now in debug mode by pressing F5. You can work on the rest of the application whilst data starts filling your index.

note icon

When I ran this example, it took around 5 minutes for the index to contain enough data. You can check how much data has been recorded by hitting the /pylon/get API endpoint. curl -H "Auth: [ACCOUNT_API_USERNAME]:[IDENTITY_APIKEY]"[recording id] Or by looking at your recording task on the DataSift dashboard, within the Pylon tab, then Recordings tab.

Analyzing Data

Now you can start writing code to analyze data in your index.

Submitting and Analysis Query

You submit analysis queries using the /pylon/analyze API endpoint.

To do so you need to specify the following parameters:

  • Analysis type - how you want the data aggregated, e.g. time series or frequency distribution
  • Threshold - for frequency distributions, the number of categories to return
  • Target - The data field of the interaction you want to analyze and plot

As a simple example, let's analyze the distribution of authors in the index by their age group.

Add the following code to your Analyze method:

var analysisParams = new
    analysis_type = "freqDist",
    parameters = new
        threshold = 5,
        target = ""

var analysis = _client.Pylon.Analyze(recordingId, analysisParams);
Console.WriteLine("\nAnalysis result: " + JsonConvert.SerializeObject(analysis.Data));

note icon

Analysis Thresholds and Limits It's important you understand analysis thresholds to get the most from Pylon. Thresholds help you work within limits that ensure the privacy of authors. Read more in our in-depth guide - Understand Audience-Size Gating.

Interpreting Your Results

Run your program to get your first analysis results.

You'll see that the result is a JSON object, which you can easily use in your application.

If when you run your program the 'redacted' value is true, then there is not enough data in your index to give you results. You'll need to wait until your index contains more data, or you could try reducing the threshold value.

Using Analysis Filters

The /pylon/analyze endpoint also allows you to specify filters to run against your index, before performing analysis:

  • Filter - specify a CSDL filter to drill into the dataset
  • Start & end - specify a time window

Your current query does not give these parameters, so the query is run against the entire dataset.

Now let's add another query to add a CSDL filter to grab a portion of the dataset, then perform analysis.

Add the following code to your Analyze method:

var analysisWithFilter = _client.Pylon.Analyze(recordingId, analysisParams, filter: " == \"female\" OR == \"female\"");
Console.WriteLine("\nAnalysis (with filter) result: " + JsonConvert.SerializeObject(analysisWithFilter.Data));

Run your program once more and take a look at the JSON output. Compare the results of the two queries.

Stopping your recording

Excellent you're all done! Before you forget, stop your data recording, otherwise you'll use up some of your recording quota.

Of course, in production solutions you'll likely want to leave your recording running permanently, or for long periods of time to collect data.

The quickest way to do this is to log in to the DataSift Dashboard. Click on the Pylon tab, then the Recordings tab within and click Stop next to your recording.

Of course you can do this using the API too!

curl -H "Auth: [ACCOUNT_API_USERNAME]:[IDENTITY_APIKEY]" -H "Content-type: application/json" -X PUT[recording id]

Next Steps

So now that you've got to grips with the API, how can you learn more?

Why not see how you can build more complex filters and queries, or learn how to add more value to data in your index?

Take a look at our Developer Guide and In-Depth Guides to deepen your knowledge of the platform.

Check out our Code Examples and start building your solution in no time.