PadCodedocs

Secrets

Keep API keys and tokens in this iPad's Keychain, out of your app's file, and send them in a Call API's headers.

A secret is an API key or a token your app sends to a web API. PadCode keeps it in this iPad's Keychain, never in your app's file and never on screen, and sends it only in a Call API step's headers. Secrets are in the Library's Data & Logic tab, under Secrets.

Data & Logic, with the Secrets section: a name box, a hidden value box with an eye, and Save to Keychain.

#Add a secret

  1. In the Library, open the Data & Logic tab.
  2. Under Secrets, type a name in the first box, like weatherKey. It starts with a letter, then uses letters, numbers or _.
  3. Type or paste the key in the Value box. It's hidden as you type; tap the eye to see it.
  4. Tap Save to Keychain. The button works once both boxes have something in them.

The secret joins the list above the boxes, with its value shown as dots. Saving a name that's already in the list replaces that secret's value.

#See, change or delete a secret

ToDo this
See the valueTap the eye beside the secret's name. Tap it again to hide it.
Change the valueTap ⋯ beside the name, choose Change Value, type the new value and tap Save. Cancel keeps the old one.
Delete itTap ⋯ beside the name and choose Delete. It's removed from the Keychain; Undo can't bring it back.
Rename itSecrets can't be renamed. Add a new one under the new name, pick it in the header, then delete the old one.

#Use a secret in Call API

  1. Open the Call API step's settings.
  2. Under Headers, tap Add field.
  3. Tap the new field's name, field1, and type the header the API asks for, like x-api-key or Authorization.
  4. Tap ⚡︎ beside it and pick the secret under Secrets.

The header's value becomes an orange chip with a key and the secret's name. When the app runs, PadCode reads the value from the Keychain and sends it with the request.

Only a Call API's Headers offer secrets. Formulas, text with braces and every other setting can't read them, so your app can't show a key on screen or send it anywhere else.

#Where secrets are kept

The note under the Secrets section sums it up: "Stored in this iPad's Keychain. Never in your app's file, never shared, never on screen. Use one in a Call API action's headers."

  • Each app has its own secrets.
  • They stay on this iPad: they don't sync through iCloud Keychain and don't move to a new iPad. On another iPad, add them again.
  • Deleting an app deletes its secrets too.

#A secret without a value

When a Call API uses a secret that has no value on this iPad, the Secrets section warns you, in orange:

“weatherKey” is used by a Call API action but has no value yet.

Tap the warning to put the name in the name box, type the value, and tap Save to Keychain.

If the app runs before then, that Call API fails with "The secret “weatherKey” has no value yet. Add it under Data & Logic → Secrets." Inside a Try, its Catch steps run; otherwise the app shows the message at the top of the screen.

#See also