Skip to main content link. Accesskey S
  • Anonymous
  • Log on
  • Help
  • IBM logo
  • IBM Connections wiki
  • All Wikis
  • Home
  • Community Articles
  • Product Documentation
  • Learning Center


Search

Advanced Search

Categories

Tag Cloud

  • 1.0
  • 1.0.x
  • 2.0
  • 2.0.1
  • 2.0.1.1
  • 2.0_media
  • 2.5
  • 2.5_deployment
  • 2.5_media
  • 2.5_performance
  • 3
  • 3.0
  • 3.0.1
  • 3.0.1_media
  • 3.0_media
  • 3_deployment
  • 8.1.1
  • 8.2
  • activities
  • administrators
  • api
  • best_practices
  • blogs
  • bookmarks
  • business_card
  • cluster
  • communities
  • community
  • community_manager
  • connections
  • connections_3
  • connections_301
  • customization
  • customize
  • customizing
  • demos
  • deploying
  • deployment
  • deployments
  • developers
  • dogear
  • Domino
  • Edge server
  • education
  • error messages
  • files
  • forums
  • getting_started
  • Help
  • home
  • home_page
  • homepage
  • how-to
  • HTTP server
  • ibm
  • index
  • installation
  • integration
  • iOS
  • ipad
  • iWidget
  • J2EE
  • javadoc
  • lc3.0
  • learning
  • lotus-connections
  • mml
  • mobile
  • Notes
  • performance
  • person_card
  • Portal
  • portlet
  • portlet_factory
  • profiles
  • proxy server
  • quickr
  • Redbooks
  • rest
  • reverse proxy server
  • Sametime
  • scenarios
  • search
  • security
  • self-paced
  • SSO
  • tags
  • test_infrastructure
  • troubleshooting
  • tuning
  • video
  • VideoFest
  • videos
  • WAI
  • WAS
  • web_seminar
  • WebAppIntegrator
  • WebSphere
  • widgets
  • wikis
InformationInformation
You are currently viewing machine translated content. IBM translation might be available. Click IBM Translated Product Documentation to see what is available.X


Home > IBM Redbooks: Customizing IBM Connections 3.0.1 > 9.2 Using IBM Connections API in different programming languages
Rate this article 1 starRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

9.2 Using IBM Connections API in different programming languages 

expanded Abstract
collapsed Abstract
No abstract provided.
Previous | Next

This section demonstrates how to use the IBM Connections APIs in different programming languages to perform the task of adding a bookmark. IBM Connections makes available all of its functionality in an easy to use REST-style API. Therefore, understanding how the API works in one module can be applied to all of the modules. Keeping this in mind, this topic focuses on creating a bookmark in the Bookmarks application using application code that is written in multiple languages.

The REST-style API that IBM Connections provides receives an HTTP request and returns an Atom document. Therefore, creating a bookmark using the API means assembling the correct HTTP request. For more details about how to assemble the Atom API request URL, refer to the IBM Connections 3.0.1 Product Documentation.
 
Note that the IBM Connections Bookmarks application was called Dogear in previous versions. However, the Boomarks API still references the term dogear in the API urls.

An API call is simply an HTTP call using a specific format.The following code snippet provides a sample Atom document that creates an entry in the Bookmarks application:

 POST /dogear/api/app?email=user@company HTTP/1.1
Host: www.company.com
Content-Type: application/atom+xml
Authorization: Basic RG9uIFA1aXhvdAAAAm9jaW5hAAR1

<?xml version="1.0" encoding="utf-8">
<entry xmlns="http://www.w3.org/2005/Atom">
<author><name>Author</name></author>
<title>IBM Connections wiki</title>
<content type="html"><![CDATA[IBM Connections wiki>]]>
</content>
<category scheme="http://www.ibm.com/xmlns/prod/sn/type" term="bookmark" />
<category term="wiki" />
<category term="Connections" />
<link href="http://www-10.lotus.com/ldd/lcwiki.nsf" />
</entry> 


The next example creates a bookmark to the IBM Connections wiki and tags it with the terms Connections and wiki. In addition, the title is set to "IBM Connections wiki" and description to "IBM Connections wiki bookmarked from Java".

Note: We use Apache Abdera in some of these code samples. Apache Abdera is an open source implementation of the Atom Syndication Format and Atom Publishing Protocol. Abdera provides a Java development toolkit that is used to quickly develop Atom clients. For more details about the Apache Abdera project, refer to the Apache Abdera project site.

Using API in Java (Core Java):
 
// Create a secure connection to the server

SocketFactory factory = SSLSocketFactory.getDefault();
Socket socket = factory.createSocket("servername", 443);
OutputStreamWriter out=new OutputStreamWriter(socket.getOutputStream(), "UTF8");

// Create the request and encode the username and password

out.write("POST /dogear/api/app?email=userEmail HTTP/1.1\r\n");
out.write("HOST: servername\r\n");
String encoding = new String(Base64.encodeBase64("user:pass".getBytes()));

out.write("Authorization: Basic " + encoding + "\r\n");
String data = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
    "<entry xmlns=\"http://www.w3.org/2005/Atom\">" +
    "<title>IBM Connections wiki</title>" +
    "<content type=\"html\"><![CDATA[IBM Connections wiki bookmarked from Java]]></content>" +
    "<category scheme=\"http://www.ibm.com/xmlns/prod/sn/type\" term=\"bookmark\" />" +
    "<category term=\"wiki\" />" +
    "<category term=\"Connections\" />" +
    "<link href=\"http://www-10.lotus.com/ldd/lcwiki.nsf\" />" +
    "</entry>";
    
out.write("Content-Length: " + data.length() + "\r\n");
out.write("Content-Type: application/atom+xml\r\n");
out.write("\r\n");
out.write(data);
out.flush();

// Process the response

BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
        System.out.println(line);
} 


Using API in Java using helper classes (Abdera):

Abdera abdera = new Abdera();
    
AbderaClient client = new AbderaClient(abdera);

client.addCredentials("https://servername", null, null, new UsernamePasswordCredentials("user","password"));

ClientResponse resp = client.get("https://servername/dogear/api/app");

Document<Service> service_doc = resp.getDocument();
Service service = service_doc.getRoot();
Collection collection = service.getCollection("My Bookmarks", "Entries");
String coll_uri = collection.getResolvedHref().toASCIIString();
    
Entry entry = abdera.newEntry();
    
entry.addLink("http://www-10.lotus.com/ldd/lcwiki.nsf");  // URL being bookmarked
entry.setTitle("IBM Connections Product Documentation");
entry.setContentAsHtml("IBM Connections wiki bookmarked from Java");
entry.addCategory("wiki");
entry.addCategory("Connections");
entry.addCategory("http://www.ibm.com/xmlns/prod/sn/type","bookmark",null);
    
// Mark private
    
entry.addCategory("http://www.ibm.com/xmlns/prod/sn/flags","private",null);

resp = client.post(coll_uri, entry);

switch(resp.getType()) {
    case SUCCESS:
        String location = resp.getLocation().toASCIIString();
        System.out.println("New entry created at: " + location);
        break;
    default:
        System.out.println("Error: " + resp.getStatusText());
}

 
Using API in Perl:
 
request LWP::UserAgent
use LWP:Debug qw(+ -conns);

my $user = "user@company.com";
my $pw = "password";
my $server = "dogear.tap.ibm.com";
my $url = "http://".$server."/api/app";
my $port = "443";

# Create a user object
my $ua = LWP::UserAgent->new;
$ua->agent("MyBookmark/0.1");
$ua->credentials($server.':'.$port,'Dogear',$user,$pw);
push @{$ua->requests_redirectableA},'POST';

# Create a request
my $req = HTTP:Request->new(POST => $url);

use XML:Generator ':pretty';

# Build XML document

my $gen = XML:Generator->new(':pretty',namespace => ["http://www.w3.org/2005/atom"]);
$content = sprintf$gen=>xml($gen->entry($gen->author("Author"),
    $gen->title("IBM Connections wiki"),
    $gen->content({type=>'html'},"IBM Connections wiki bookmared from Perl.");
    $gen->category({scheme=>"http://www.ibm.com/xmlns/prod/sn/type",term=>"bookmark"}),
    $gen->category({term=>"wiki"});
    $gen->category({term=>"Connections"});
    $gen->link({href=>"http://www-10.lotus.com/ldd/lcwiki.nsf"})
    )
);    

# Set request content
$req->content_type('application/atom+xml');
$req->content($content);

# Pass request to the user agent and get a response
my $res = $ua->request($req);

# Check the outcome of the response
if ($res->is_sucess) {
    print "Bookmark posted.\n";
}
else {
    print $res->status_line, "\n";
}


Using API in VBScript

url = "https://dogear.tap.ibm.com/api/app"

entry = "<?xml version="1.0" encoding="utf-8">" &_
                        "<entry xmlns="http://www.w3.org/2005/Atom">" &_
                        "<author><name>Author</name></author>" &_
                        "<title>IBM Connections wiki</title>" &_
                        "<content type="html"><![CDATA[IBM Connections wiki bookmarked from VBScript>]]>" &_
                        "</content>" &_
                        "<category scheme="http://www.ibm.com/xmlns/prod/sn/type" term="bookmark" />" &_
                        "<category term="wiki" />" &_
                        "<category term="Connections" />" &_
                        "<link href="http://www-10.lotus.com/ldd/lcwiki.nsf" />" &_
                        "</entry>"

Set objHTTP = CreateObject("Microsoft.XMLHTTP")
objHTTP.open "POST", url, False, "johndoe@ibm.com", "password")
objHTTP.setRequestHeader "Content-Type", "application/atom+xml"
objHTTP.send entry
Document.Write objHTTP.statusText
Set objHTTP = Nothing 


Parent topic: 9.0 Using the API

expanded Article information
collapsed Article information
Category:
IBM Redbooks: Customizing IBM Connections 3.0.1
Tags:
Redbooks

This Version: Version 2 November 22, 2011 12:02:32 PM by Amanda J Bauman  IBMer

expanded Attachments (0)
collapsed Attachments (0)

 


expanded Versions (2)
collapsed Versions (2)
Version Comparison     
Version Date Changed by               Summary of changes
This version (2) Nov 22, 2011 12:02:32 PM Amanda J Bauman  
1 Nov 21, 2011 1:07:15 PM Amanda J Bauman  
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedSubscribe to RSSHelpAbout
  • All Lotus and WebSphere Portal wikis
  • IBM developerWorks
  • IBM Software support
  • IBM Social Business User Experience Blog
  • IBMSocialBizUX on Twitter
  • IBMSocialBizUX on Facebook
  • Lotus product forums
  • IBM Social Business UX blog
  • IBM Collaboration Solutions
  • Recently added feedRecently added
  • Recently edited feedRecently edited
  • Recently added comments feedRecently Added Comments
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Contact IBM
  • IBM Terms of use
  • Wiki terms of use