msgraph@0.4.0
Functions
- create(resource, data, callback)
- get(path, query, callback)
- getDrive(specifier, name, [callback])
- getFile(pathOrId, options, [callback])
- getFolder(pathOrId, options, [callback])
- sheetToBuffer(rows, options)
- uploadFile(resource, data, callback)
create
create(resource, data, callback) ⇒ Operation
Create some resource in msgraph
Kind: global function
Access: public
Param | Type | Description |
---|---|---|
resource | string | The type of entity that will be created |
data | object | The data to create the new resource |
callback | function | An optional callback function |
Example
create("applications", {"displayName": "My App"})
get
get(path, query, callback) ⇒ Operation
Make a GET request to msgraph resource
Kind: global function
Access: public
Param | Type | Description |
---|---|---|
path | string | Path to resource |
query | object | Query, Headers and Authentication parameters |
callback | function | (Optional) Callback function |
Example
get('sites/root/lists')
getDrive
getDrive(specifier, name, [callback]) ⇒ Operation
Get a Drive or SharePoint document library. The drive metadata will be written
to state.drives, where it can be used by other adaptor functions.
Pass { id } to get a drive by id or { id, owner } to get default drive for
some parent resource, like a group
Kind: global function
Access: public
Param | Type | Default | Description |
---|---|---|---|
specifier | Object | A definition of the drive to retrieve - id {string} - The ID of the resource or owner. - owner {string} - The type of drive owner (e.g. sites, groups). | |
name | string | The local name of the drive used to write to state.drives, ie, state.drives[name] | |
[callback] | function | s => s | (Optional) Callback function |
Example (Get a drive by ID)
getDrive({ id: "YXzpkoLwR06bxC8tNdg71m" })
Example (Get the default drive for a site)
getDrive({ id: "openfn.sharepoint.com", owner: "sites" })
getFile
getFile(pathOrId, options, [callback]) ⇒ Operation
Get file metadata or file content.
Kind: global function
Access: public
Param | Type | Default | Description |
---|---|---|---|
pathOrId | string | A path to a file or file id | |
options | object | (Optional) Query parameters | |
[callback] | function | s => s | (Optional) Callback function |
Example (Get a file by ID)
getFile('01LUM6XOGRONYNTZ26DBBJPTN5IFTQPBIW')
Example (Get a file for a named drive by id)
getFile("01LUM6XOGRONYNTZ26DBBJPTN5IFTQPBIW",{ driveName: "mydrive"})
getFolder
getFolder(pathOrId, options, [callback]) ⇒ Operation
Get the contents or metadata of a folder.
Kind: global function
Access: public
Param | Type | Default | Description |
---|---|---|---|
pathOrId | string | A path to a folder or folder id | |
options | object | (Optional) Query parameters | |
[callback] | function | s => s | (Optional) Callback function |
Example (Get a folder by ID)
getFolder('01LUM6XOCKDTZKQC7AVZF2VMHE2I3O6OY3')
Example (Get a folder for a named drive by id)
getFolder("01LUM6XOCKDTZKQC7AVZF2VMHE2I3O6OY3",{ driveName: "mydrive"})
request
request ⇒ This is an asynchronous function that sends a request to a specified URL with optional parameters and headers, and returns the response data in JSON format.
Kind: global constant
Returns: The request
function is returning the parsed JSON data from the response of the HTTP
request made to the specified url
with the given params
and method
. If there is an error in
the response, the function will throw an error.
Param | Type | Description |
---|---|---|
url | string | The URL of the API endpoint that the request is being made to. |
[options] | object | An object containing any additional parameters to be sent with the request, such as query parameters or request body data. It is an optional parameter and defaults to an empty object if not provided. |
sheetToBuffer
sheetToBuffer(rows, options) ⇒
The function sheetToBuffer
takes in rows, options and optional callback, It creates a workbook
and worksheet using the rows, appends the worksheet to the workbook, and returns the workbook as a
buffer.
Kind: global function
Returns: a buffer containing the Excel file in state.buffer
.
Access: public
Param | Type | Description |
---|---|---|
rows | The rows parameter is an array of objects representing the data to be written to the Excel sheet. Each object in the array represents a row in the sheet, and the keys of the object represent the column headers. The values of the object represent the data in each cell of the row. | |
options | The options parameter is an object that contains additional configuration options | |
[options.wsName] | String | Worksheet name i.e 32 Characters |
[options.bookType] | String | File format of the exported file, Default is 'xlsx'. See here for the function. It can have the following properties: |
Example (Create a buffer containing excel file with `xlsx` output format )
sheetToBuffer('$.data[*]', {
wsName: 'Invalid Grant Codes',
bookType: 'xlsx',
});
uploadFile
uploadFile(resource, data, callback) ⇒ Operation
Upload a file to a drive
Kind: global function
Access: public
Param | Type | Description |
---|---|---|
resource | Object | Resource Object |
[resource.driveId] | String | Drive Id |
[resource.driveId] | String | Site Id |
[resource.folderId] | String | Parent folder id |
[resource.contentType] | String | Resource content-type |
[resource.onConflict] | String | Specify conflict behavior if file with the same name exists. Can be "rename |
data | Object | A buffer containing the file. |
callback | function | Optional callback function |
Example (Upload Excel file to a drive using `driveId` and `parantItemId`)
uploadFile(
state => ({
driveId: state.driveId,
folderId: state.folderId,
fileName: `Tracker.xlsx`,
}),
state => state.buffer
);
Example (Upload Excel file to a SharePoint drive using `siteId` and `parantItemId`)
uploadFile(
state => ({
siteId: state.siteId,
folderId: state.folderId,
fileName: `Report.xlsx`,
}),
state => state.buffer
);