---
title: JavaScript
slug: javascript
docTags: 
createdAt: 2020-04-06T10:02:22.000Z
---

Learn how to build and manage your integrations using Pathfix client library. Get documentation, example code, tutorials, and more.

## Common Concepts

The pathfix oauth library is loaded by including the helper.js in the following manner.&#x20;

```html

<script src="https://labs.pathfix.com/helper.js"
 data-user-id="[your application user email or id]" 
 data-public-key="[your application public key in pathfix]" 
 id="pinc.helper" modules="pinc.oauth.min" ></script>
                        
```



:::hint{type="info"}
Although the oauth.js can be loaded from the same location it will not work independently. It needs a few dependencies that are loaded by the helper.js
:::







## Pathfix, OnLoad

When the Pathfix helper library is ready it calls back a global function on the page. This is the place you should be attaching handlers to monitor the loading of other libraries. See example below\...



```html


<html>
    <head>
        <!--Pathfix Code-->
        <script>
            function $pinc_onload(){
                //Pathfix library is ready, are you :)
                //monitor events of the oauth library
                $pinc.events.on("$pinc.oauth","ready",()=>{
                    /*Good place to check if the previous authorizations
                    by the user and alter the display of your page.  
                    */
                },true)

            }
        </script>

        <script src="https://labs.pathfix.com/helper.js" data-user-id="jane.doe@example.com" data-public-key="APPLICATION-ID-OR-PUBLIC-KEY" id="pinc.helper" modules="pinc.oauth.min" ></script>
                            
    </head>        
</html>


```







## Event Handlers

Events to all Pathfix libraries are attached using a standard syntax.

```javascript


//adding an event listener
$pinc.events.on(library,eventName,callback,forceInvoke);

//removing an event listener
$pinc.events.off(library,eventName,callback);


```

### Arguments

| library     | required | Name of the library that you'd want to attach to. For oauth library use <font color="#ce9178">"$pinc.oauth"</font> as a string. |
| ----------- | -------- | ------------------------------------------------------------------------------------------------------------------------------- |
| eventName   | required | Eventname to be sent across as string eg. <font color="#ce9178">"ready"</font>                                                  |
| callback    | required | Event handler reference.                                                                                                        |
| forceInvoke | optional | If true, it forces your callback to be invoked if the event was fired before you attached your handler.                         |

### Example

```javascript

$pinc.events.on("$pinc.oauth","ready",callback,true);
```

## Method Calls

Most method calls in Pathfix need callback as the final argument. Method calls are made to the library using their object reference. Below is the list of libraries available.



| $pinc       | All global functions are accessible using this object. |
| ----------- | ------------------------------------------------------ |
| $pinc.oauth | Pathfix Oauth library.                                 |





