Skip to content
This page View Markdown Open in ChatGPT Open in Claude

Set redis key

Stores values in the external Redis of API Maker, in the namespace of the account : sessions, captchas, counters, anything a later call or another server needs. Each key can expire on its own.

Method POST
URL /api/system-api/admin/set-redis-key : admin is the user path of your account
Body an array of { key, value, ttl?, NX? }
Answer data : true
From code g.sys.cache.setKey

The call

Body
[
    { "key": "session:user123", "value": "{\"cart\":3}", "ttl": 3600 },
    { "key": "captcha:abc", "value": "7H2K", "ttl": 180, "NX": true }
]
Answer
{ "success": true, "statusCode": 200, "data": true }
Key Meaning
key The name. It is stored under the namespace of the account.
value A string. Serialise objects with JSON.stringify.
ttl Seconds before the key expires. Without it, redisValueExpireInSeconds of the configuration (7200 by default) : keys never live forever.
NX true : write only when the key does not exist yet.

From code

await g.sys.cache.setKey('session:user123', JSON.stringify({ cart: 3 }), 3600);
await g.sys.cache.setKey([ { key: 'captcha:abc', value: '7H2K', ttl: 180, NX: true } ]);
  • The Redis dashboard shows the keys with their TTL and lets you edit them.

Access and settings

  • Over HTTP, a system API answers once its settings give it apiAccessType: TOKEN_ACCESS (the token of an API user whose group grants this system API, in x-am-authorization) or IS_PUBLIC. Without settings it is NO_ACCESS : your code calls it through g.sys, the admin panel tests it, and an HTTP call is refused.
  • The settings can also cache the answer or require person tokens (authProviders) ; pre and post hooks run around it like around any API.
  • The request headers apply : x-am-response-case, x-am-content-type-response, x-am-internationalization, x-am-tenant-username…

Errors

Code When
400 The body is wrong : the message names the missing or invalid key.
401 No valid API user token, or the API is NO_ACCESS : You are not authorized to access this API.
403 No group grants this system API.