Integrate with Microsoft Intune - IntegrationHub Data Retrieval
Keeping with the times, IntegrationHub is immensely powerful in it's performance, easy maintainability and integral foundation as part of the NOW platform. Data can be retrieved using a flow data stream, however, this does require an Enterprise IntegrationHub license (check with your account manager) which does put it out of reach for a number of organisations.
Connection Alias
To use flow designer with the OAuth credential record we created earlier, a connection and credential alias has to be created.
- Search for Connection & Credential Aliases in the application navigator and create a new record
- Set a sensible name and a connection type of HTTP
- Save the record and create a new connection record via the related list
- Set the connection URL to https://graph.microsoft.com
- If you tested the credentials in the second article, you would have already created a credential record. If you didn't, use the magnifying glass to pop out the reference field table and create a new record. Select the OAuth entity profile created in the earlier article.
- Save the record
Create Data Stream Action
Creating a flow designer data stream couldn't be easier and hopefully, this article will help with some foundational knowledge. If you're wanting more of a background of data streams and a step by step of creating one, I recommend walking through this course Data Stream Actions Objectives | ServiceNow Developer
- Within Flow Designer select the new button and Data Stream. If you can't see an option for data stream, make sure you have the relevant plugins installed as documented in the introduction article to this series
- Give the data stream action a sensible name such as Get Intune Computers and save the record
Data Stream actions allow for large, paginated, response bodies by cycling through data retrieval based on a starting input and pagination variables.
- From the left, select Inputs and create two input records of type string. Label the first as nextLink and the second as base.
- Expand the inputs using the arrow toggle on the right.
- Set the nextLink default value to our query input of beta/deviceManagement/managedDevices?filter=deviceType eq 'desktop' or deviceType eq 'macMDM' or deviceType eq 'winEmbedded' or deviceType eq 'surfaceHub' or deviceType eq 'windowsRT'
- Set the base default value to https://graph.microsoft.com/
- Make sure both variables are mandatory and select save. It's important to remember that, unlike workflow, there isn't auto-saving so regular saves will prevent any data losses.
- Select the Request menu from the left navigator and set the data retrieval mechanism to REST Step and enable pagination
- Select Pagination Setup step and use the blue/green plus sign to the right of the form to create two new variables
- Copy the setup below into the variables
- Enter the following script into the script section
(function paginate(variables, pageResponse) {
if (!gs.nil(variables.nextLink)){
variables.nextLink = variables.nextLink.replace(variables.base, '');
variables.getNextPage = true;
} else {
variables.nextLink = "";
variables.getNextPage = false;
}
})(variables, pageResponse);
- Navigate to Rest Step and set the connection alias to the one created previously
- Set the resource path to the pagination setup step nextLink
- Select Parsing and set the two fields to JSON Splitter and Script Parsing respectively
- Under the splitter step, set the format to JSON and set the path to $.value
- In the script step, enter the script below. This maps the fields we want to keep from the managedDevice object returned by the Graph API
(function parse(inputs, outputs) {
var record = JSON.parse(inputs.sourceItem);
outputs.targetObject.id = record.id;
outputs.targetObject.userId = record.userId;
outputs.targetObject.deviceName = record.deviceName;
outputs.targetObject.enrolledDateTime = record.enrolledDateTime;
outputs.targetObject.operatingSystem = record.operatingSystem;
outputs.targetObject.complianceState = record.complianceState;
outputs.targetObject.osVersion = record.osVersion;
outputs.targetObject.emailAddress = record.emailAddress;
outputs.targetObject.model=record.model;
outputs.targetObject.manufacturer=record.manufacturer;
outputs.targetObject.serialNumber = record.serialNumber;
outputs.targetObject.wiFiMacAddress = record.wiFiMacAddress;
outputs.targetObject.managedDeviceOwnerType = record.managedDeviceOwnerType;
outputs.targetObject.jailBroken = record.jailBroken;
outputs.targetObject.userDisplayName = record.userDisplayName;
outputs.targetObject.deviceEnrollmentType = record.deviceEnrollmentType;
outputs.targetObject.managementAgent = record.managementAgent;
outputs.targetObject.totalStorageSpaceInBytes = record.totalStorageSpaceInBytes;
outputs.targetObject.deviceType = record.deviceType;
outputs.targetObject.freeStorageSpaceInBytes = record.freeStorageSpaceInBytes;
outputs.targetObject.ethernetMacAddress = record.ethernetMacAddress;
outputs.targetObject.chassisType = record.chassisType;
outputs.targetObject.userPrincipalName = record.userPrincipalName;
outputs.targetObject.connectionAliasId = inputs.fd_data.action_inputs.connectionalias.sys_id
})(inputs, outputs)
- Navigate to Outputs and select Edit Outputs
- Select Create Output with a label and name of targetObject and type of Object
- Use the small plus option to add properties to the object. For each output line in the script, a relating property has to be created in the data stream output. This is unfortunately a repetitive process and the important thing is to ensure the name of the property matches that of the name in the script.
- Save the data stream and test it
- In the execution details, you should see something similar to the below
Create Data Source
The data stream action provides the mechanism to retrieve the data we want, we now need to create the data source that'll take the retrieved data and store it within a staging table ready for transformation.
- Navigate to System Import Sets via the application navigator and create a new data source
- Set a name to identify the source, i.e Intune Computer Devices
- Set a label for the table the system will create for us, i.e Intune Computer Devices IMP
- Set the type to Data Stream
- Check Data in single column
- Select your data stream action. If your action isn't visible, make sure it's set to published.
- Save the record and use the Test Load 20 Records UI Action to pull some example data.
Labels:
https://www.servicenow.com/community/developer-articles/integrate-with-microsoft-intune-integrationhub-data-retrieval/ta-p/2318684
