Search code examples
javascriptapilinkedin-api

Linkedin connections search first job title for each connection


I'm trying to get all the current job titles of my connections from linkedin. I managed to do it but only by requesting ALL jobtitles and then grabbing the first one. That's inefficient. I'm doing something simmillar to this:

function onLinkedInAuth() {
  IN.API.Profile("me")
    .fields(["firstName", "lastName", "positions:(title)"])
    .result(function(result) { ($"#profile").html(JSON.stringify(result))} );
}

I know I can add a param and get a count of lets say 5 (.params({"count": 10...)) but that only seems to work for connections not titles of connections...I've tried "positions:(title)[0]" but it did not work.

Any thoughts? is this even possible?

Thanks.


Solution

  • To grab the current job, you need to request the is-current field as well. Then simply iterate through the returned positions collection checking the is-current value for each position. Your call would be:

    function onLinkedInAuth() {
      IN.API.Profile("me")
        .fields(["firstName", "lastName", "positions:(title,isCurrent)"])
        .result(function(result) { ($"#profile").html(JSON.stringify(result))} );
    }