Skip to main content

msgraph@0.7.7

create(resource, data, callback)
get(path, query, callback)
getDrive(specifier, name, [callback])
getFile(pathOrId, options, [callback])
getFolder(pathOrId, options, [callback])
uploadFile(resource, data, callback)

This adaptor exports the following namespaced functions:

Utils.sheetToBuffer(rows, options)

This adaptor exports the following from common:

cursor()
dataPath()
dataValue()
dateFns
each()
field()
fields()
fn()
fnIf()
lastReferenceValue()
merge()
parseCsv()
sourceValue()

Functions

create

create(resource, data, callback) ⇒ Operation

Create some resource in msgraph

ParamTypeDescription
resourcestringThe type of entity that will be created
dataobjectThe data to create the new resource
callbackfunctionAn optional callback function

Example

create("applications", {"displayName": "My App"})

get

get(path, query, callback) ⇒ Operation

Make a GET request to msgraph resource

ParamTypeDescription
pathstringPath to resource
queryobjectQuery, Headers and Authentication parameters
callbackfunction(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

ParamTypeDefaultDescription
specifierObjectA 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).
namestringThe local name of the drive used to write to state.drives, ie, state.drives[name]
[callback]functions => 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.

ParamTypeDefaultDescription
pathOrIdstringA path to a file or file id
optionsobject(Optional) Query parameters
[callback]functions => 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.

ParamTypeDefaultDescription
pathOrIdstringA path to a folder or folder id
optionsobject(Optional) Query parameters
[callback]functions => 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"})

uploadFile

uploadFile(resource, data, callback) ⇒ Operation

Upload a file to a drive

ParamTypeDescription
resourceObjectResource Object
[resource.driveId]StringDrive Id
[resource.driveId]StringSite Id
[resource.folderId]StringParent folder id
[resource.contentType]StringResource content-type
[resource.onConflict]StringSpecify conflict behavior if file with the same name exists. Can be "rename
dataObjectA buffer containing the file.
callbackfunctionOptional 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
);

Utils

These functions belong to the Utils namespace.

Utils.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.

Returns: a buffer containing the Excel file in state.buffer.

ParamTypeDescription
rowsThe 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.
optionsThe options parameter is an object that contains additional configuration options
[options.wsName]StringWorksheet name i.e 32 Characters
[options.bookType]StringFile 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',
});