Created
April 28, 2017 17:58
-
-
Save aroach/1f036fafdc141173a0efc057cd431d5d to your computer and use it in GitHub Desktop.
APIC-EM example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
var util = require('util'); | |
exports.handler = (context, callback) => { | |
// Add your code here | |
var body = JSON.stringify({ | |
'username': 'devnetuser', | |
'password': 'Cisco123!', | |
}) | |
var options ={ | |
url: 'https://sandboxapic.cisco.com/api/v1/ticket', | |
headers: { | |
'content-type': 'application/json' | |
}, | |
body: body | |
}; | |
request.post(options, function(error, response, body) { | |
if (error) throw error; | |
// console.log(response); | |
// console.log('body', body); | |
var serviceTicket = JSON.parse(body); | |
request.get({ | |
url: 'https://sandboxapic.cisco.com/api/v1/network-device', | |
headers: { | |
'X-Auth-Token': serviceTicket.response.serviceTicket | |
} | |
}, function (error, response, body) { | |
if (error) throw error; | |
// console.log(response); | |
// console.log('host body', body); | |
var networkDevices = JSON.parse(body); | |
var result = []; | |
networkDevices.response.map(function(_device) { | |
var device = { | |
type: _device.type, | |
macAddress: _device.macAddress, | |
reachabilityFailureReason: _device.reachabilityFailureReason | |
} | |
result.push(device); | |
}); | |
logger.info(JSON.stringify(result)) | |
callback(JSON.stringify(result)) | |
}) | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment