← Back to Recipes

Encrypt parameters

Example to encrypt your parameters before create or update an item.

Steps#

1. Import your crypto library#

2. Encrypt parameters#

Encrypt the parameters payload.

3. Create item#

Using your Pluggy API_KEY, create the item using your previously encrypted payload as parameters inside the request body.

Code#

import crypto from 'crypto'
 
const rsaPublicKeyPem =
  'RSA public key in PEM format got from Pluggy operations'
 
const payload = {
  user: 'user-ok',
  password: 'password-ok',
}
 
async function main() {
  const RSAPublicKey = Buffer.from(rsaPublicKeyPem)
  const encryptedPayload = crypto
    .publicEncrypt(RSAPublicKey, Buffer.from(JSON.stringify(payload)))
    .toString('base64')
  console.log('Payload encrypted:', encryptedPayload)
 
  const item = await fetch('https://api.pluggy.ai/items', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-API-KEY': 'YOUR_PLUGGY_API_KEY',
    },
    body: JSON.stringify({
      connectorId: 2,
      parameters: encryptedPayload,
      webhookUrl: 'https://example.com/webhook',
    }),
  })
    .then((res) => res.json())
    .catch((err) => console.error(err))
 
  console.log('Item created:', item)
}
 
main()