We've had a number of questions from people wanting to use C# with our REST API. There are many ways to do this, but since .NET is a strongly typed language and provides many API clients, we're going to use RestSharp for our example.

RestSharp is a simple REST and HTTP client for .NET available on Github, If you're new to Github, you can find everything you need to get started here,

 

To start, let's create a new .NET application that references the RestSharp library. And here's how simple it is to make a request using .NET + RestSharp :

 

RestClient client = new RestSharp.RestClient
                             {
                                 BaseUrl = "https://secure.eloqua.com/API/1.0/",
                                 Authenticator = new HttpBasicAuthenticator(instancename + "\\" + username, password)
                             };

var request = new RestSharp.RestRequest(Method.GET)
                              {Resource = "/assets/emails?search=*&page=1&count=10"};

 

The response for this call looks as follows :

 

{
  "elements": [
    {
      "type": "Email",
      "currentStatus": "Draft",
      "id": "5907",
      "createdAt": "1370264668",
      "createdBy": "476",
      "depth": "minimal",
      "folderId": "42",
      "name": "Fred - test",
      "permissions": "fullControl",
      "updatedAt": "1370264668",
      "updatedBy": "476",
      "htmlContent": {
        "type": "StructuredHtmlContent",
        "contentSource": "editor"
      }
    },
    {
      "type": "Email",
      "currentStatus": "Draft",
      "id": "5906",
      "createdAt": "1370230460",
      "createdBy": "381",
      "depth": "minimal",
      "folderId": "42",
      "name": "Fred Sample",
      "permissions": "fullControl",
      "updatedAt": "1370230460",
      "updatedBy": "381",
      "htmlContent": {
        "type": "StructuredHtmlContent",
        "contentSource": "editor"
      }
    },
...
],  "page":   "pageSize": 10,
  "total": 3530
}

 

We hope that you find this useful.

 

Thanks,

Fred