Skip to main content

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

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

Kind: global function
Access: public

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

Kind: global function
Access: public

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.

Kind: global function
Access: public

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.

Kind: global function
Access: public

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"})

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.

ParamTypeDescription
urlstringThe URL of the API endpoint that the request is being made to.
[options]objectAn 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

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',
});

uploadFile

uploadFile(resource, data, callback) ⇒ Operation Upload a file to a drive

Kind: global function
Access: public

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
);