Bind a secret to a function

SDK platic.tools.functions.bindSecret()

Bind an existing secret to a slot in secretSlots. Use this when a slot in secrets[] is missing. Send the secret's id, not its value.

Example

await platic.tools.functions.bindSecret("fn_123", { slot: "API_KEY", secretId: "sec_123" });

Path parameters

ParameterTypeDescriptionRequired
functionIdstringFunction ID✓

Request body

{
  "slot": "API_KEY",
  "secretId": "5d0c7a1e9b3f4a6c8e2d1f0b7a9c3e5d6f8a0b2c4d6e8f1a3b5c7d9e0f2a4b6c"
}
FieldTypeDescriptionRequired
slotstringA declared slot, like API_KEY. secret:API_KEY is also accepted✓
secretIdstringSecret ID, from List secrets or Create a secret✓

Response

data has the complete function, with the fields of Get a function. The slot ends up in bound.

{
  "status": "success",
  "message": "Secret bound",
  "data": {
    "id": "Hk2s9QmXc1",
    "name": "tax_id_lookup",
    "status": "draft",
    "toolName": "fn_tax_id_lookup",
    "toolId": null,
    "secrets": [
      {
        "slot": "API_KEY",
        "origin": "https://api.example.com",
        "state": "bound",
        "secretId": "5d0c7a1e9b3f4a6c8e2d1f0b7a9c3e5d6f8a0b2c4d6e8f1a3b5c7d9e0f2a4b6c"
      }
    ],
    "nextStep": "Test it with POST /v1/tools/functions/Hk2s9QmXc1/test, then publish it."
  }
}

Some fields are left out of the example.

Errors

Statusdetails.codeWhen
400INVALID_REQUESTslot or secretId is missing, or the slot is not declared. details.issues has the list of problems
403FORBIDDEN or INSUFFICIENT_SCOPEThe credential cannot use secrets or does not have write access to Integrations
404NOT_FOUNDThe function or the secret does not exist in this workspace
501FUNCTION_SECRETS_UNAVAILABLEBinding secrets is not available at the moment

Notes

  • The secret is authorized only for that slot's origin. Platica puts it in http.fetch calls to that origin; the code only sees a placeholder.
  • Binding another secret to the same slot replaces the previous one.
  • If you later change allowedDomains or secretSlots with Update a function, bind the secrets again.
  • The same secret can be bound to several functions and to other tools.