How to create HERE apps and generate API keys in batch

Request

You may want to create 100 HERE apps and create API keys for them and you want to do it automatically.

Solution

Use the HERE OLP CLI tool with Python to create apps and API keys in batch with a program or script.

Sample Code

Here is a piece of sample code in Python to automate the process:

`import json

import json
import subprocess
import re

# prepare an array to store the new app IDs, HRNs, and API keys
apps = []

# Define the regular expression pattern to match the app HRNs and IDs
pattern = r'hrn:here:account::YOUR_REALM_ID:app/([a-zA-Z0-9]+)'

# this script only generates 3 new apps, change the number 4 to 101 to create 100 new apps
for i in range(1,4):
    # create new app
    olp_cli = f'olp app create app-{i}' # the apps are named like app-1, app-2, and so on
    result = subprocess.run(olp_cli, shell=True, capture_output=True, text=True)

    # retrieve app ID and HRN from the command response
    result = re.search(pattern, result.stdout)
    if result:
        # print out the new app ID
        print("new app created:", result.group(1))
        # create new app object and push it to apps array
        app = {
            "app_id": result.group(1),
            "app_hrn": result.group(0)
        }
        apps.append(app)

# create API keys for the new apps
for app in apps:
    # run the OLP CLI tool to create the API key
    olp_cli = f'olp app key api create {app["app_hrn"]} api_key --json'
    result = subprocess.run(olp_cli, shell=True, capture_output=True, text=True)
    # push the API key to the app object in the app array
    result_json = json.loads(result.stdout)
    app["api_key"] = result_json["apiKeyId"]

# check the final result
print(json.dumps(apps, indent=2))



Note that the realm ID "YOUR_REALM_ID" is a placeholder which should be replaced with your own realm ID.

The output of the script is an app list with app IDs, HRNs, and API keys as follows:



Note

Check the documentation in reference for how to setup OLP CLI tool and delete apps or API keys with it.

To delete the apps or API keys in bulk, feed your request, the docs, and the above sample code to AI tools.


Reference

OLP CLI - App Workflows
OLP CLI - Get Started

Tag

  • OLP CLI
  • Create Apps
  • Create API keys
  • In Bulk
  • HERE Platform