Getting Started with the JavaScript SDK

Easily integrate LinkedIn into your web applications

    LinkedIn's JavaScript SDK is a convienent way to enable LinkedIn integrations within your websites and web-based applications, without the need for any back-end programming.  The major benefits of using the SDK include:

    • Easy authentication of LinkedIn members via functions that abstract all of the complexity of the authentication process away from you.
    • A convienent generic API call wrapper that allows you to make authenticated REST API calls.

    Once you have familiarized yourself with the information in this guide, you will be ready to use the LinkedIn JavaScript SDK to Sign In with LinkedIn, Share with LinkedIn and Manage Company Pages with LinkedIn.

    SDK Compatibility

    The JavaScript SDK is currently supported in the following web browsers:

    • Firefox 3+
    • Chrome (latest)
    • Safari 5+
    • IE 7+

    Note: The JavaScript SDK is not compatible with iOS 5+.

    Configure your LinkedIn application for JavaScript SDK use

    Using the JavaScript SDK requires you to have an application registered with LinkedIn.  If you have not already done so, create an application. If you have an existing application, select it to modify its settings.

    In order to ensure that other applications cannot fraudulently represent themselves as your own using the JavaScript SDK, you must configure a list of valid domains where your application lives that LinkedIn is allowed to trust.  This is done by adding your domain(s) to the "Valid SDK Domains" field in your application's configuration under "JavaScript Settings":

    Provide a comma-separated list of fully qualified domain names, including the protocol (i.e. http, https) and any non-standard port numbers (other than ports 80 or 443).

    Failure to configure a JavaScript API domain will result in the following error in your browser's JavaScript console whenever your webpage attempts to initialize the SDK:

    javascript console error
    Error: You must specify a valid JavaScript API Domain as part of this key's configuration.

    Initialize the SDK in your webpage

    In order to use any of the functionality available in the SDK, you need to include the library in your webpage.  It is a script file that is pulled in real-time from LinkedIn, and is not downloaded and hosted locally with your project.

    Place the following <script> block into the <head> section of your HTML and provide all of the argument values that are relevant to your application's needs:

    <script type="text/javascript" src="//">
        api_key:   [API_KEY]
        onLoad:    [ONLOAD]
        authorize: [AUTHORIZE]
        lang:      [LANG_LOCALE]
    api_keyYour LinkedIn application's API key.  You can find your API key value in My Apps.Yes
    onLoadA comma-separated list of the names of Javascript functions that you want the SDK to execute once it has successfully loaded itself.
    authorizeA boolean value that, when set to true, will instruct the SDK to check for a cookie containing an existing authentication token for the user.  If found, the user will be automatically logged in when the SDK is invoked.

    The default value is false, which will require the user to log in every page load, regardless of previous successful logins.
    langA language code to localize any of the UI text that the SDK outputs.  The default language is US English (en_US).

    See Language Codes for a complete list of possible values.


    The line breaks between the arguments within the <script></script> tags are important since there is no other form of field separator.  If you are using a templating language or code minifier that strips whitespace from your rendered HTML, be aware that you will need to make an exception to preserve the line-breaks within this <script> tag, otherwise they will not be parsed properly.

    Additional SDK functions

    The following is a list of miscellaneous tasks that you can perform using the JavaScript SDK:

    Request authorization for a user

    You can request additional privileges by requiring the user to authorize. It's recommended to call this method in response to a user action to avoid popup blockers. If the user is not logged in, it will present the popup authorization window.

    IN.User.authorize(callbackFunction, callbackScope);

    This function takes the following arguments:

    • callbackFunction - Function
      a function to call when the user is authorized. If the user is already logged in, callbackFunction will fire immediately
    • callbackScope - Object
      an optional scope to run callbackFunction in. Defaults to the window scope

    Check if the current user is authorized

    You can use the IN.User.isAuthorized() to see if the user has granted access to your application.  It returns a boolean true if the user is authorized, otherwise it returns false.

    Make an authenticated API call

    The JavaScript SDK enables you to easily make authenticated calls to the LinkedIn REST API using the generic call wrapper:


    This function takes the following arguments:

    • default url() - String 
      The API URL to invoke: should not include
    • method() - String 
      The HTTP method to use (GET, POST, PUT, or DELETE). If omitted, uses a default value of GET.
    • body() - String 
      For APIs with a POST body, POSTs and PUTs, this is the URL encoded post body. For GET requests, this does nothing.

    Refresh the user's session

    The default user session is 30 minutes (after which the OAuth token expires). If you want to be sure the user is authorized and that your environment has a valid OAuth token, you can request a refresh of the user's session by calling the IN.User.refresh() function.  This will refresh their token for an additional 30 minutes. 

    Repeated continual use of the refresh() function to keep a member indefinitely logged in can result in your application being disabled.  Use this call sparingly.

    Log the user out

    You can log the user out of your application using the following code. In the JavaScript SDK, logging the user out is defined as logging them out of the LinkedIn network (i.e. clearing cookies). This does not revoke or delete the user's authorization grant for your application.

    IN.User.logout(callbackFunction, callbackScope);

    This function takes the following arguments:

    • callbackFunction - Function - a function to call when the user is logged out.
    • callbackScope - Object - an optional scope to run callbackFunction in. Defaults to the window scope

    Handling LinkedIn events

    Events provide a way for the developer to hook into interesting moments within the JavaScript SDK. These include user session state changes, as well as when the framework is loaded. All events are subscribed to through the same universal Event framework:

    IN.Event.on(IN, eventName, callback, callbackScope, extraData);
    IN.Event.onOnce(IN, eventName, callback, callbackScope, extraData);

    Invoking onOnce will limit the event's callback to happening a single time.

    • IN
      This is the global IN object, the root namespace of the LinkedIn JavaScript SDK. This means you want to listen to the framework's global events. In the future, it may be possible to subscribe to events from specific components.
    • eventName - String 
      This is the name of the event. Supported events are:                         
      • auth - The user has authorized this application
      • frameworkLoaded - Fires before systemReady when all foundation JavaScript has been loaded from Usage for this event is intended to be internal-only for now.
      • logout - The user has logged out of the application
      • systemReady - Fired with the system is completely ready for execution. onLoad events can fire
    • callback - Function 
      A callback function to execute when eventName fires
    • callbackScope - Object 
      An optional scope to execute callback in. If not set, will default to the window scope
    • extraData - Object 
      Provide an additional object to callback. If not set, will default to {}