Platform

Platform

A place for Apptio product users to learn, connect, share and grow together.

 View Only

DataLink API sample scripts 

Tue January 26, 2016 01:15 PM

◆ Applies to: TBM Studio 12.0 and later

 

DataLink 4 supports a programmable REST API that allows you to execute any action that is currently available in the UI through the API. This is useful for a number of scenarios:

  • Trigger a connector to run and receive a success/fail message
  • Run multiple connectors in a sequence, for example, based on a success/fail message run another connector
  • Update the password or any parameter for one or multiple connectors given a list of connector names/IDs
  • Update or disable the scheduling information for one or multiple connectors given a list of connector names/IDs

 

Attached are two sample scripts written in Python:

  1. Rest_utils.py - is a small, basic library that can be used to perform common tasks with our API.
  2. Samples.py - leverages rest_utils to demonstrate some of use cases above.

To run the scripts, call the functions in samples.py.

 

Further API documentation is available from the product by clicking the gear icon. Please provide feedback and feel free to post new scripts to Community for others to take advantage of.

2016-01-26_1000.png

2016-01-26_1001.png

 

For more information, see The Apptio API




#Datalink

Statistics
0 Favorited
49 Views
1 Files
0 Shares
11 Downloads
Attachment(s)
zip file
SampleScriptsV2.zip   4 KB   1 version
Uploaded - Tue October 29, 2024

Comments

Tue March 27, 2018 06:58 PM

Hey thanks so much for putting this out here! Very instructive and helpful!


#Datalink

Thu December 07, 2017 04:41 PM

Updated sample scripts to adapt to changes in the JSON format, and to include an example of API Key support.


#Datalink

Fri August 18, 2017 05:23 AM

@Beau Alexander


#Datalink

Thu March 02, 2017 03:45 AM

Wow Erik, this is fantastic! Thank you so much for taking the time to give back to Community!

Since we're on the topic of PowerShell, I wanted to provide a cross-reference for you and any readers to make sure you knew about @Jose GALA's PowerShell cmdlet for Active Directory. It's in the Data Connections space, where we're building a space for everybody to talk about how they're sourcing their data.


#Datalink

Wed March 01, 2017 02:10 PM

In my company's version of the TBM Office, we don't use a lot of Python.  Probably should, and I'll put that on my list of skills to build... For those who are in the same boat as me and want to try to use the DataLink 4 API using PowerShell, I wrote up a segment of 'recipe ingredients' from my experimentation that will allow folks who are stuck & looking for a little push to get going again.

 

Thanks to @Dan Kelly for the encouragement and feedback.

 

Enjoy.

 

----- begin -----

<#
#
# Note, these are EXAMPLES of the way I chose to implement the API methods in PowerShell!
#
# This is based on the information found in the DataLink API guide found within the DataLink 4 web interface
# ... and a lot of web searches on various aspects of utilizing invoke-restmethod in PowerShell!
#
# This is not written in order to actually operate as a script. This is meant as a kind-of "hamburger helper"
# for those working through & testing the API to understand the process on their own
#
# That is to say, "Use at your own risk"
#
#>


$frontdoorURI = "https://frontdoor.apptio.com/service/nonuilogin"
$DLBaseURI = "https://dl-<YOURCOMPANYHERE>-manager.apptio.com/api/v1/resource/agent"


#create a header package for authentication
$authvals = @{ping_uname=$user;ping_pwd=$password} | convertto-json

 

#use invoke-restmethod to connect to Frontdoor. Return a session variable named "mysession" to be used to get the session token
$results = invoke-restmethod -uri $frontdoorURI -method post -body $authvals -contenttype 'application/json' -sessionvariable mysession

 

#retrieve the session token
$cookies = $mysession.Cookies.getCookies($frontdoorURI)
$token = @{$cookies.name = $cookies.value}

 

<#
#
# At this point, there should be a successful login, and the appropriate session token is in $token
#
# Now to take some action --
# - get AGENTS
# - get CONNECTORS
# - EXECUTE connector
#>

 

#get the AGENTS on the datalink instance. Returns high-level data for the agents in $agents
$agents = invoke-restmethod -uri $DLBaseURI -method get -headers $tokenComp


#get all the CONNECTORS on a specific AGENT -- note the GET method needs the '-headers' to include the session token. This returns data for all connectors on the Agent
$DLOperatingURI = $DLBaseURI + "/" + $agents.id + "/connector"
$connectors = invoke-restmethod -uri ($DLOperatingURI.id+"?include=name,type") -method get -headers $token


#EXECUTE a particular CONNECTOR on a specific agent
$DLConnectorURL = $DLOperatingURI + "/" + $someConnector.ConnectorID


#Now, create the command statement in JSON format
$task_exec = @{ "task" = "ExecuteConnector" } | convertto-json

 

#send the execute command here. Note the POST requires the token in '-headers', same as GET, and '-body' contains our task execution statement
$execConnector = invoke-restmethod -uri ($DLConnectorURL+"/execute") -method post -headers $token -body $task_exec -contenttype 'application/json'

----- end -----


#Datalink