LinkedIn API with LUCEE



I’m “playing” with LinkedIn API.

The first step is naturally to be able to log into LinkedIn via its authorization requirements.

According to its doc, it’s the following URL plus parameters:

URL parameters:


I have valid values for all the parameters.

If I run the URL with parameters and their respective values by hand, it works as expected, however, when I put the above URL with parameters and values into a variable, and with username and password for the CFHTTP call, it prompts for username and password.

I wonder if any of you have experienced the same, and how did you overcome it?

Thanks in advance.

P.S. It would be nice to be able to add new category such as LinkedIn or API etc…


There is a long-standing bug with cfhttp which prevents the username and password attributes being sent over HTTPS:

Try using cfhttpparam to send the authorization header as described in that bug report.


This is how I attempt to bypass the bug as you suggested except that (values for the username and password etc. posted here are not authentic).

<cfhttpparam type="header" name="username" value="">
<cfhttpparam type="header" name="password" value="donliPWD">

<cfhttpparam type="header" name="Authorization" value="Basic #ToBase64('')#">


403 Forbidden

(1) if output cfhttp.statusCode only, it’s 200 (looking good),
however, if added, cfhttp.fileContent,
it asked for username and password

I’m a bit puzzled here.



I haven’t used the LinkedIn API before, but I think you may be misunderstanding the authorization/authentication process. According to the docs, the URL you’re trying to call is for your users to visit so that they can grant your app the permissions it needs. You should send them there via a cflocation with the appropriate url parameters, rather than cfhttp.

Once they’ve granted permission (Step 2 in the docs), you’ll need cfhttp to make a POST request to the API and get your access token (Step 3). Once you have that, you’ll be able to make authenticated calls (Step 4) also using cfhttp.

A username/password doesn’t seem to be needed at any stage.


Very helpful. At step 3, once I return results such as

How can we extract the access_token value and expires_in value out of it?

The output looks like an array, thus, I attempted #cfhttp.fileContent["access_token"]#, but it looks like #cfhttp.filecontent# is complex string. What’s a good way to get these two values and we move to next step?

Many thanks.



result = DeserializeJSON( cfhttp.fileContent );
access_token = result.access_token;


Awesome. It’s working now. Many thanks!


LinkedIn API is a tough nut to crack. I’m now attempting to test its “Share” feature.

The following code generated “405 Method Not Allowed”. Why? How could we fix it? Many thanks.

<cfset stuff = {
  "comment": "Test posting: check out!",
  "content": {
	"title": "Test posting a title",
    "description": "Test posting to LinkedIn via LinkedIn's API !"
  "visibility": {
    "code": "anyone"
<cfhttp url="" method="post">
	<cfhttpparam type="header" name="Authorization" value="Bearer #access_token#">
	<cfhttpparam type="header" name="Content-Type" value="application/json">
	<cfhttpparam type="body" value='#serializeJSON(stuff)#'>

#cfhttp.statusCode# <br>


When posting JSON rather than XML, it seems you need to send this header in addition to the Content-Type:

<cfhttpparam type="header" name="x-li-format" value="json">


Good thought, Julian, I’ve added this cfhttpparam line right under the “Content-Type” one,
and yet, still same error of "405 Method Not Allowed ". Thanks.


In addition, I have w_share permission (I assume it would suffice to share a post or a comment something).


I used LinkedIn API console, able to send a share via POST. Here’s the console output for the request (except the access_token value for security):

POST /v1/people/~/shares?oauth2_access_token=AQXy288jskskdjsjsdssfy5ypKcBkdb_LKo43oTBR-1sMktFyQJZYfOd1gfFW8gkhAXnSZDjBu-C8yMZ5VS83-51CDlntGreiDDJylEIGkmZIDkkdp5mJdDV_-MF8nrcPEXqE1_IXI1p77_O1NWTmM20GDV8ytZYWlKA58Vl6_nOzJBFyvgMps-NW99qMaHT-3M&format=json HTTP/1.1
Content-Length: 356

  "comment": "Check out!",
  "content":  {
    "title": "LinkedIn Developers Resources",
    "description": "Leverage LinkedIn's APIs to maximize engagement",
    "submitted-url": "",
    "submitted-image-url": ""
  "visibility":  {
    "code": "anyone"

Based on the above, so, I’ve revised the code accordingly, specifically as follows (var stuff has been defined and we have the #access_token# as well of course):

<cfhttp url="" method="POST">
	<cfhttpparam type="header" name="Content-Type" value="application/json">
	<cfhttpparam type="header" name="x-li-format" value="json">
	<cfhttpparam type="body" value='#serializeJSON(stuff)#'>

And yet, we still have the same error of “405 Method Not Allowed”. It’s mind-boggling. Thanks.


The error suggests a problem with the request method, but it’s definitely POST in the docs, and the content type headers seem fine. You are missing the “submitted-url” and “submitted-image-url” values from your share data, but unlikely that would cause the error. Does the reponse include a more detailed “message” field of any kind?


Here’s the response, and method-wise, only POST or PUT would make sense, I’ve tried both with the same error, thanks.

HTTP/1.1 201 Created
Wed, 28 Jun 2017 14:08:46 GMT

  "updateKey": "UPDATE-12717617-6285831129270403072",
  "updateUrl": ""


Are you sure that’s the right response? You said it was a 405?


Sorry I wasn’t clear, that response with 201 was from the LInkedIn API console.


After some offline discussion, it seems the issue is with the way Lucee encodes the url in cfhttp by default which was causing the tilde character (~) in the LinkedIn endpoint not to be recognized.

The fix is just to add encodeUrl=false to the cfhttp tag like so:

<cfhttp url="" method="POST" encodeUrl=false>
	<cfhttpparam type="header" name="Authorization" value="Bearer #access_token#">
	<cfhttpparam type="header" name="Content-Type" value="application/json">
	<cfhttpparam type="header" name="x-li-format" value="json">
	<cfhttpparam type="body" value='#serializeJSON(stuff)#'>


Great work, Julian, much appreciated!


Hi Julian, I wonder if you have some contact at Linked API because I’d like to find out if it’s API is able to let one retrieve update of anyone on the LinkedIn (with his/her user id). I’ve googled for answers and stackoverflow as well, however, to no avail. Thus, only their own API engineer would know.
Many thanks.


Sorry, Don. I’ve never even used LinkedIn or its API, let alone have any contacts there.