Fun with TDI (aka SDI) and AD/Domino/Cnx – Part 2 – Upload a file to Connections
Files can be directly uploaded to IBM Connections through the API via a HTTP request. This is documented in the IBM Connections 4.5 API Documentation i.e. when we want to update a file inside Connections we find some informations on how to this here.
Unfortunately the documentation has no examples (as Carl Tyler nicely described in “The Domino Designer documentation team screwed us all”) and is far away from being perfect. Starting point for me was to use the SBT API Explorer on Greenhouse and/or a local Rest client (I’m using the Cocoa Rest client on my OS X machine).
So if you want to update a file inside Connections you have to do a PUT request on:
- /files/basic/api/myuserlibrary/document/{document-id}/media (if the authenticated user is the owner of the file)
- /files/basic/api/userlibrary/{person-id-of-owner}/document/{document-id}/media
Easiest way to find the {person-id-of-owner} and the {document-id} is to open the file in the browser and do a right click on “Feed for…” and copy the link.
Now paste the link into a text file and you will find what you are looking for, i.e.
https://greenhouse.lotus.com/files/basic/api/userlibrary/c3d3e940-a5ec-102e-9eea-9e53070fc933/document/151d047d-6553-46cf-9434-fbcc7da2b489/feed?category=comment
Now we have to use this link inside a HTTP Client Connector in the TDI CE, following screenshot shows you my upload connector:
-
The authentication user is the owner of this file so I only had to use the {document-id}
… /files/basic/api/myuserlibrary/document/627d6ac1-dcf3-4e7d-ab85-fe91de991ad3/media as URL.
-
Request Method is PUT, we want to send an updated file
-
File to HTTP body is the file path to the CSV with the users data which was created in step 6, in this case D:\BelsoftContacts.csv
-
We will upload a CSV file therefore we set text/comma-separated-values as Content Type
A Cryptographic key prevents unauthorized access to Connections data, this cryptographic nonce (number used once) key has to be used for the PUT request. You can get this key via a URI (files_server/basic/api/nonce) but it’s much easier to use the HTTP Client Connector in CallReply Mode and get the key with the first call and then use this key for the Reply/PUT request.
First get the key in the Input Map (http.x-update-nonce):
and then use it in the Output Map:
I only added a Default Success Hook at the end which deletes the CSV file (or you can implement some error handling if needed).
In the next part later this week I will show you how you can create a comment to this file and update a Wiki page with the TDI script, stay tuned.