Select to view content in your preferred language

How To Access ArcGIS Monitor Data Through the API

1666
10
01-19-2024 12:28 PM
GeoJosh
Esri Regular Contributor
5 10 1,666

Table of Contents

 

Introduction

ArcGIS Monitor 2023 collects and generates endless amounts of useful data. The software itself ships with a number of tools to help you make sense of all this data; Collections help you organize components into logical groupings and Analysis Views help you identify trends in the data. There may be times that you need to programmatically access the data so that you can extend ArcGIS Monitor in a custom way. To do so, you must first acquire an authentication token.

In this article, I will demonstrate how to acquire an authentication token for ArcGIS Monitor using Postman. Postman is a tool that is popular in the web development world for testing and interacting with APIs. It allows you to define requests and organize them into collections. You can learn more about Postman here. After we have acquired an access token, I will demonstrate how to include the token in a request to ArcGIS Monitor to obtain data.

Please note: The ArcGIS Monitor API is currently a beta feature and is not supported by Esri Support. Please use caution and thoroughly test these workflows in non-production environments first.

 

Obtain an Access Token

1. In Postman, create a new Collection.

GeoJosh_0-1705596833359.png

 

2. Create a new POST request inside the new Collection

GeoJosh_3-1705597046875.pngGeoJosh_1-1705596895329.png

 

 

 

3. In the URL textbox, type in the URL to the token generation endpoint.

GeoJosh_0-1705611573660.png

 

4. Click Body, select raw, and choose JSON for content type.

GeoJosh_0-1705676421110.png

 

5. The request body object should have two keys: username and password. Define a new JSON object and add these keys with their respective values:

GeoJosh_1-1705676475598.png

 

6. Send the request! The response body will contain four keys but I only want to call out two of them right now:

  • access_token: The token that will be used to authenticate future requests.
  • expires_in: How long (in seconds) the token can be used before another needs to be generated.

GeoJosh_2-1705676519426.png

 

7. Copy the value of access_token and paste it in your favorite text editor.

 

Use the Access Token to Obtain Data

In this section, we will walk through how to use the access token generated above to query ArcGIS Monitor for metrics data.

 

1. Follow steps 2 through 4 above to create a new request. When defining the URL in step 3, use the URL to the metrics data query endpoint instead:

GeoJosh_7-1705673943722.png

 

2. Click Authorization and choose Bearer Token for type. For Token, paste the access token from step 7 above.

GeoJosh_8-1705674090943.png

 

4. Click Body, select raw, and choose JSON for content type.

GeoJosh_9-1705674785068.png

 

5. I am interested in the metrics data for a specific metric, so I will specify a where clause that targets a metric by it's ID:

GeoJosh_10-1705674990334.png

 

6. Send the request! The body will contain a key called features which is an array of metrics data for the metric I specified.

GeoJosh_11-1705675062775.png

 

What Next?

In this article, I demonstrate how to use a REST client (Postman) to get an access token for ArcGIS Monitor and how to use that token to obtain Monitor data. Manually obtaining this data via Postman might not be ideal, so please use these examples as guides that help you extend the ArcGIS Monitor application  through scripting and other applications.

 

Learn More

ArcGIS Monitor

ArcGIS Monitor Information Model

ArcGIS Monitor on Esri Community

Introduction to ArcGIS Monitor

10 Comments
MaurusErni1
Occasional Explorer

Hi @GeoJosh 

Thanks for your blog how to use the REST API. I was able to get a token and fetch some JSONs from ArcGIS Monitor.

We're using ArcGIS Monitor 2023.3.1 and would like to use the REST Api to import/export configuration and settings from stage to stage. So it would be great to know the full REST API.

The REST API OpenAPI documentation URL should be reachable at: https://xxxx:30443/arcgis/apidoc
This was mentioned here and here .

Calling this URL with ArcGIS Monitor 2023.3.1 returns a 404 (not found). Any hint how/where to reach the REST API OpenAPI documentation?

Regards
Maurus Erni

GeoJosh
Esri Regular Contributor

Hi @MaurusErni1,

As mentioned in the the blog post, the API is currently in beta. The development team made the decision to deprecate the endpoint you mentioned until the API is ready to enter a fully supported state.

Josh

MaurusErni1
Occasional Explorer

Hi @GeoJosh 

Thanks for the clarification.

Regards, Maurus

Sander
by
Occasional Contributor

Hi Josh,

Does your statement only aplies to "REST API OpenAPI documentation URL" (https://xxxx:30443/arcgis/apidoc), or for API access at all? We noticed that the token endpoint "https://<myagm>:30443/arcgis/auth/token"?  (AGM 2023.3.1) is also not reachable.

kind regards

Sander

GeoJosh
Esri Regular Contributor

Hi @Sander,

As mentioned in the the blog post, the API is currently in beta. The development team made the decision to deprecate the endpoint you mentioned until the API is ready to enter a fully supported state.

This statement only applies to https://xxxx:30443/arcgis/apidoc. The token endpoint should still be reachable via POST request at 2023.3.1.

Josh

GeorgePan
Occasional Contributor

@GeoJosh 

Hi Josh,

I have tested to query  data from all the items in the ArcGIS Monitor 2023.3 Information Model. They all work well. But it is hard to find any documents / examples on how to add / delete / update them by REST API. Would you mind providing some examples of Python code or using Postman to make that happen? Such as add a new Collection by Python or Postman? 

I heard the ArcGIS Monitor team have blocked something in version 2023.1 REST API, are those add / delete / update functions blocked in version 2023.3 too? Is it possible to use PostgreSQL's SQL  statement to implement them based on the relationships of tables without using REST API?

Most ESRI users might have tons of components in the existing ArcGIS Monitor 10.8.1 - 10.6.1. It will be tough for us to manually move them to version 2023.3. It will be a great help for us to make GIS deployment / upgrading automations if we can do that by PowerShell or Python scripts.

Thanks,

George

Pat_Gallagher
Regular Contributor

Josh,

I would like to second the request for additional information on using the REST API. The information you provided in this blog was very helpful, but trying to expand beyond what you have is difficult as I am not finding any documentation to support the new API. The ESRI Video from April 2023 references the deprecated apidoc endpoint. 

Is it possible to either provide some additional examples or an update on when the API will leave the Beta?

GEOKID
by
Emerging Contributor

Here's a useful tip: you can modify the URL of step 4 to target the specific component you need. For instance, "https://<agmhost>/arcgis/monitoring/metrics/query". Next, utilize the expression builder to add the item you wish to query, such as a metric or metric data. Set an expression to generate the desired data table. Then, switch the expression builder to the JSON option and copy it into the Postman request for step 5.

For instance I use this query on .../metrics/query to obtain last metric of utilized storage of my server

{
  "resource": "metrics",
  "where": "(metrics.r_id = 'storage_capacity_utilized' AND metrics.component_name = '<server name> Drive C')"
}

 

I hope this contributes. 😊

MarcHoogerwerf_EsriNL
Occasional Contributor

@GeoJosh 

Hi Josh,

Is there any update on the status or ETA of the ArcGIS Monitor REST API? I've been searching for information on version 2024.0 but could not find anything yet.

regards,

 

Marc

DerekLaw
Esri Esteemed Contributor

Hi @MarcHoogerwerf_EsriNL,

Is there any update on the status or ETA of the ArcGIS Monitor REST API?

We're expecting to release more information about the ArcGIS Monitor REST API in 2025. Sorry for the delay.

Hope this helps,