# Dynatrace Metrics API into Jupyter Notebook

**URL:** <https://community.dynatrace.com/t/dynatrace-metrics-api-into-jupyter-notebook/18697>\
**Category:** Dynatrace API\
**Tags:** integrations, reports, python, dynatrace-api\
**Created:** [March 9, 2020, 2:29pm UTC](https://community.dynatrace.com/t/dynatrace-metrics-api-into-jupyter-notebook/18697 "2020-03-09T14:29:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![grogers](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/grogers/32/25969_2.png) [@grogers](https://community.dynatrace.com/u/grogers)\
**Post date:** [March 9, 2020, 2:29pm UTC](https://community.dynatrace.com/t/dynatrace-metrics-api-into-jupyter-notebook/18697/1 "2020-03-09T14:29:25Z")

</div>

Has anyone used the Dynatrace Metrics API (v2) to pull data into a Jupyter notebook? I’m close, but need to pivot the default data format into something more friendly.

```auto
url = '{0}/api/v2/metrics/query?metricSelector={1}&from={2}&to={3}&resolution=2m&entitySelector=type({4}),entityId({5})'.format(base_url,metric,from_time,to_time,entity_type,entity_id)

result = requests.get(url, headers=headers)

result_json = result.json()

df = pd.DataFrame.from_dict(result_json['result'][0]['data'])

df

```

![24048-capture.jpg](https://global.discourse-cdn.com/dynatrace/original/3X/8/c/8ca82627c77e87f1797edc51759d4d56a52db4bf.jpeg)

I’m trying to gather 4-5 different metrics into a notebook to present to management.

---

<div class="post-metadata">

**Author:** ![grogers](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/grogers/32/25969_2.png) [@grogers](https://community.dynatrace.com/u/grogers)\
**Post date:** [March 9, 2020, 3:33pm UTC](https://community.dynatrace.com/t/dynatrace-metrics-api-into-jupyter-notebook/18697/2 "2020-03-09T15:33:53Z")

</div>

Got it:

```auto
metric = 'builtin:service.response.time'
entity_type = 'SERVICE'
entity_id = 'SERVICE-64FED8674FB7BA98'
from_time = 'now-1h'
to_time = 'now'

url = '{0}/api/v2/metrics/query?metricSelector={1}&from={2}&to={3}&resolution=2m&entitySelector=type({4}),entityId({5})'.format(base_url,metric,from_time,to_time,entity_type,entity_id)

result = requests.get(url, headers=headers)

result_json = result.json()

in_data = result_json['result'][0]['data'][0]
del in_data['dimensions']

df = pd.DataFrame.from_dict(in_data)

df.timestamps = pd.to_datetime(df.timestamps, unit='ms', utc=True)
df.timestamps = df.timestamps.dt.tz_convert('US/Central')

df.plot(x='timestamps', y='values')

```
