Can't use Gs.BatchGetGatewayConnectionStats to get gateways stats in batch

Greetings everyone.

I’d like to consult my gateways stats in batch instead of a making a request for each gateway, for that purpose I’m using this endpoint:

Gs.BatchGetGatewayConnectionStats

So I’m issuing the request using cURL in the following way:

curl -X POST "https://eu1.cloud.thethings.network/api/v3/gs/gateways/connection/stats" \
     -H "Authorization:Bearer NNSXS.xxxyyyzzz" \
     -H "Content-Type:application/json" \
     -d '{"gateway_ids":["gateway-rak-7268"]}'

However, the request is not successful. I get the following error:

"code":3,"message":"ReadObjectCB: expect { or n, but found \", error found in #10 byte of ...|ay_ids\":[\"gateway-ra|..., bigger context ...|{\"gateway_ids\":[\"gateway-rak-7268\"]}|..."}

As I could understand, the error is related to the quotes. Somehow the quotes get scaped (I think so because of the \" in the error message)

Reading through the forum, I was able to find this post and I tried the approach suggested by the poster, so I made the request like:

curl -X POST "https://eu1.cloud.thethings.network/api/v3/gs/gateways/connection/stats" \
     -H "Authorization:Bearer NNSXS.xxxyyyzzz" \
     -H "Content-Type:application/json" \
     -d '{\"gateway_ids\":[\"gateway-rak-7268"]}'

I still get an error message after issuing the request:

{"code":3,"message":"invalid character '\\\\' looking for beginning of object key string"}

Thanks in advance for taking the time to read.

Best,

1 Like

Try writing it this way

{"gateway_ids":[{"gateway_id":"gateway-rak-7268"}]}

Greetings @jssani thanks for your quick reply.

I’ve tried to make the request in the way that you proposed, that is:

curl -X POST "https://eu1.cloud.thethings.network/api/v3/gs/gateways/connection/stats" \
     -H "Authorization:Bearer NNSXS.xxyyyzzz" \
     -H "Content-Type:application/json" \
     -d '{"gateway_ids":[{"gateway_id": "gateway-rak-7268"}]}'

And the error actually disappear, however, I get an empty JSON as response and the response code is “None” as can be seen in the image below:

Also, I’d like to ask you about the proper usage of the “field_mask” field in order to issue the request, since it is not quite clear.
As far as I understand, it is not mandatory to be included in the body’s request, only the “gateway_ids” field is mandatory.

image

Thanks in advance.

They are a list of fields that you want returning in the response - some you get regardless anyway, but if you need a particular field, you can specify it there.

This works for me in python

import requests
from requests.structures import CaseInsensitiveDict
import json

url = "https://tenant.eu1.cloud.thethings.industries/api/v3/gs/gateways/connection/stats"

headers = CaseInsensitiveDict()
headers["Authorization"] = "Bearer NNSXS.XXXXX"
headers["Content-Type"] = "application/json"

data = """
{
    "gateway_ids": [
	{"gateway_id":"gw157"},
    {"gateway_id":"gw153"},
    {"gateway_id":"gw150"}
    ]
}
"""


resp = requests.post(url, headers=headers, data=data)

json_data = resp.json()
json_formatted_str = json.dumps(json_data, indent=2)

print(json_formatted_str)

Greetings @jssani,
Thanks for the quick reply by the way.

I’ve just tried what you suggested but I still get exactly the same behavior.

I’ve tried getting the gateways’ stats from two different accounts because I was suspecting that maybe I was requesting the info from a gateway which has been inactive and, for that reason, it might not have stats to consult, however, the following screenshot is the request for a bunch of gateways that I’m certain to be active and operating flawlessly.

Thanks in advance