• Hello game master! Welcome to our growing community. Please take a moment to Register (top right button, see how: Slides).

    If you use Campaign Logger, you can use the same login details - we've linked the app to this forum for secure and easy single sign-on for you.

    And please drop by the Introductions thread and say hi.

Generator API Access

JochenL

CL Byte Sprite
Staff member
Adamantium WoA
Wizard of Story
Wizard of Combat
Gamer Lifestyle
Borderland Explorer
This is for Developers!

Our generator service has an API: https://generator.campaign-logger.com/swagger/index.html
This API is also used by our own UI: https://generator-ui.campaign-logger.com/

You can use it to:
  • retrieve your generators (GET)
  • update them (PATCH or PUT)
  • create new ones (POST)
  • delete them (DELETE) - There is no recycle bin; gone is gone
  • validate them
  • generate results with them
  • manage execute tokens for embedding generator publically
To call any of these API endpoints, you need a token.
You can retrieve this token in the legacy UI of CL: https://legacy.app.campaign-logger.com/
It is available in the new CL UI, but not yet visible there.

Get the token to the Generator API:
  • Visit https://legacy.app.campaign-logger.com/
  • Login (same username/email and password as for the new UI or your forum login)
  • Click the Cog symbol
  • Click "Show API Keys"
  • Copy the read/write key (the second one) - the read-only key will not work
In your API call, add a header "Authorization: Bearer <your copied API key>".
That's it, you should now be able to access the Generator API.
 

JochenL

CL Byte Sprite
Staff member
Adamantium WoA
Wizard of Story
Wizard of Combat
Gamer Lifestyle
Borderland Explorer
Here is a minimal python example to get you started: https://github.com/open-campaign-logger/cl-generator-rest-api-demo

Python:
import http.client

def loadAllGenerators(token):
    cxn = http.client.HTTPSConnection("generator.campaign-logger.com")
    cxn.request("GET", "/api2/generators", headers={
        "Content-Type": "application/json",
        "Authorization": "Bearer " + token
        })
    response = cxn.getresponse()

    print(response.status, response.reason)
    print(response.read().decode('utf-8'))

loadAllGenerators("your_token_here")
 

Hannu

Mythras Guru
Gold WoA
Wizard of Story
Wizard of Combat
I had to modify the above:
import http.client
import ssl

def loadAllGenerators(token):
# Create a custom SSL context
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE

# Create a connection to the API server with SSL context
cxn = http.client.HTTPSConnection("generator.campaign-logger.com", context=context)

try:
# Send a GET request
cxn.request("GET", "/api2/generators", headers={
"Content-Type": "application/json",
"Authorization": "Bearer " + token
})

# Get the response from the server
response = cxn.getresponse()

# Print the status code and reason for the response
print(response.status, response.reason)

# Print the response body
data = response.read().decode('utf-8')
print(data)

except Exception as e:
print("An error occurred:", e)

finally:
# Close the connection
cxn.close()

loadAllGenerators("your_token_here")
 
Top