---
title: $pinc
slug: dollarpinc
docTags: 
createdAt: 2020-06-10T06:57:23.000Z
---

The `$pinc` library gives you access to some common functions used across Pathfix. Below are the list of common scenarios where you might use the library.



## Get the Pathfix API Call URL or Revoke URL

**Syntax**

`$pinc.getPathfixUrl(providerName, publicKey, userId)`

`$pinc.getPathfixRevokeUrl(providerName, publicKey, userId)`

**Remarks**

| Arguments    | Description                                                                                                                       |
| ------------ | --------------------------------------------------------------------------------------------------------------------------------- |
| providerName | Internal provider name. See [Provider reference](docId\:Z26CDo6omB40W2fyMu_UT)                                                    |
| publicKey    | optional: Defaults to the public key specified in the [data-public-key](docId\:YbjxRAKFGEIsTDWi312Ol) attribute of the script tag |
| userId       | optional: Defaults to the [data-user-id](docId\:SIx7fJ9iQb5Z2gV_AA96R) attribute of the script tag                                |

**Example**

```javascript

//The code uses jQuery
function postMessage(){
    //Request Pathfix to build the API call url
    var url = $pinc.getPathfixUrl("googlecalendar");
    var pfxPayload = {
        "url":"https://www.googleapis.com/calendar/v3/users/me/calendarList",
        "method":"GET"
    }
    $post(url, JSON.stringify(pfxPayload)).always(response=>{
        console.log(response);
    })
}

function disconnect(){
    //Request Pathfix to build the User Disconnect/Revoke authorization url
    var url = $pinc.getPathfixRevokeUrl("googlecalendar");
    //no payload is needed
    $post(url).always(response=>{
        console.log(response);
    })
}

```





## Read Contents of a file before uploading to Online Storage

**Syntax**

`$pinc.fileRead(FileReader, callback)`

Returns

`{"type": "HTTP_MIME_TYPE","content": "file_content", uploadObject:{}}`

**Remarks**

Method Call

- FileReader - <font color="#eb144c">required</font>,<font color="">  Javascript FileReader Object</font>
- callback- callback function reference

Return

- content - The raw file content.
- uploadObject - Pass as a parameter to the payload when uploading the file using Pathfix passthrough [Endpoints](docId\:mAzd9101PgJPioxiaZbkT)

**Example**

```javascript


// fileInput is an HTML input element: <input type="file" id="myfileinput" multiple>
var fileInput = document.getElementById("myfileinput");

// files is a FileList object (similar to NodeList)
var files = fileInput.files;
var file;

// loop through files
for (var i = 0; i < files.length; i++) {

    // get item
    file = files.item(i);
    //or
    file = files[i];

    //PATHFIX USAGE SAMPLE
    var pfxFile = $pinc.fileRead(file,response => {
        var pfxPayload = {
                    "url": `https://storage.googleapis.com/upload/storage/v1/b/${options.bucket}/o/`,
                    "method": "POST",
                    "headers": {
                        "x-payload-type": "file"
                    },
                    "payload": response.uploadObject
                }
        _upload
    });
}


```

Extended code from [developer.mozilla.org](https://developer.mozilla.org/en-US/docs/Web/API/FileList)
