0

I am callig and endpoint and am trying to get some of the values in it using bash.

I was able to perform the operation using python's json and dict functions but I am having trouble figuring out how to convert it to a bash based script that is using jq to parse and process the requests response.

r = requests.get(
    "url",
    headers={
        "Authorization" : "Bot {}".format(bot_token)
    }
)
for val in r.json():
    if val['name'] == "val_name":
        return val['id']
return "null"

the response I get from that api call is

[
    {
        "id": "1123",
        "last_message_id": "1123",
        "last_pin_timestamp": "2020-03-02T20:12:59.378000+00:00",
        "type": 0,
        "name": "daName",
        "position": 4,
        "parent_id": "544433",
        "topic": "theTopic",
        "guild_id": "123322",
        "permission_overwrites": [
            {
                "id": "1231232",
                "type": "role",
                "allow": 0,
                "deny": 213123
            }
        ],
        "nsfw": false,
        "rate_limit_per_user": 0
    },
    {
        "id": "123123123",
        "type": 2,
        "name": "daName2",
        "position": 0,
        "parent_id": "123123123",
        "bitrate": 64000,
        "user_limit": 0,
        "guild_id": "234141232",
        "permission_overwrites": [
            {
                "id": "2345242342",
                "type": "role",
                "allow": 0,
                "deny": 0
            },
            {
                "id": "`12123123",
                "type": "role",
                "allow": 0,
                "deny": 402663472
            }
        ],
        "nsfw": false
    },
modernNeo
  • 137
  • 9

0 Answers0