In our last post we introduced Eloqua's REST API with a simple example using PHP. Given the popularity of Node.js - we wanted to do a similar introduction for the JavaScript community.

 

In this post, we'll walk through a simple example in Node.js to demonstrate how easy it is to work with Eloqua's REST API. The code sample invokes a GET request with basic authentication to retrieve a list of Emails from the Eloqua application. The use cases vary, but we’re essentially providing a hook for retrieving a list of data from Eloqua's API. We're sure you'll find some great and exciting ways to use this.

 

For now, let's get started with a simple request to Eloqua's REST API using Node.js

 

// Include the request library for Node.js
var request = require('request');

//  Basic Authentication credentials
var username = "Company\\Username";
var password = "xxxxx";
var authenticationHeader = "Basic " + new Buffer(username + ":" + password).toString("base64");

// Search for Emails with name containing Demand
request(
    {
        url : "https://secure.eloqua.com/API/REST/1.0/assets/emails?search=*Demand*&page=1&count=50&depth=minimal",
        headers : { "Authorization" : authenticationHeader }
    },
    function (error, response, body) {
        console.log(body);
    }
);

 

The response for this call looks as follows :

 

{ 
"elements": [ 
  { 
"type": "Email",
"currentStatus": "Draft", 
"id": "86013",
"createdAt": "1370981173", 
"createdBy": "9",
"depth": "minimal",
"folderId": "1422",
"name": "Demand.html", 
"permissions": "fullControl", 
"updatedAt": "1370981173", 
"updatedBy": "9",
"htmlContent": { 
     "type": "RawHtmlContent", 
     "contentSource": "upload" 
      } 
 }, 
 { 
"type": "Email",
"currentStatus": "Draft", 
"id": "69830",
"createdAt": "1362380717", 
"createdBy": "244",
"depth": "minimal",
"folderId": "1422",
  "name": "Demand Sample", 
"permissions": "fullControl", 
"updatedAt": "1362380784", 
"updatedBy": "244",
"htmlContent": { 
     "type": "RawHtmlContent", 
     "contentSource": "upload" 
      } 
  }, 
   ... 
  ], 
"page": 1, 
"pageSize": 10, 
"total": 130 
} 

 

I hope this was a helpful introduction to the REST API and how easy it is to work with. We'll explore more of the REST API in future posts.

 

Thanks,

Fred