Skip to content
Go To Dashboard

Using Services

In this guide, you’ll verify a phone number using Sapiom — no Prelude account required.

  1. Sign in to the Sapiom Dashboard and generate an API key.

    Add your API key to your environment:

    Terminal window
    export SAPIOM_API_KEY="your_api_key_here"
  2. Terminal window
    npm install @sapiom/fetch
  3. Create a file called verify.ts and add the following code:

    import { createFetch } from '@sapiom/fetch';
    const fetch = createFetch({
    apiKey: process.env.SAPIOM_API_KEY!,
    });
    async function sendVerificationCode(phoneNumber: string) {
    const response = await fetch(
    'https://prelude.services.sapiom.ai/verifications',
    {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
    target: {
    type: 'phone_number',
    value: phoneNumber,
    },
    }),
    }
    );
    const data = await response.json();
    console.log('Verification sent!');
    console.log('Verification ID:', data.id);
    return data.id;
    }
    // Replace with your phone number (E.164 format)
    sendVerificationCode('+15551234567');

    Run it:

    Terminal window
    npx tsx verify.ts

    You’ll receive a text message with a verification code.

  4. Update your file to check the code:

    import { createFetch } from '@sapiom/fetch';
    const fetch = createFetch({
    apiKey: process.env.SAPIOM_API_KEY!,
    });
    async function checkVerificationCode(verificationId: string, code: string) {
    const response = await fetch(
    'https://prelude.services.sapiom.ai/verifications/check',
    {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
    verificationRequestId: verificationId,
    code: code,
    }),
    }
    );
    const data = await response.json();
    if (data.status === 'success') {
    console.log('Phone number verified!');
    } else {
    console.log('Verification failed:', data.status);
    }
    }
    // Use the verification ID from step 3 and the code you received
    checkVerificationCode('your-verification-id', '123456');

    Run it with your verification ID and the code from your text message:

    Terminal window
    npx tsx verify.ts
  5. Open the Sapiom Dashboard to see your verification transaction.

    You just verified a phone number with zero Prelude account setup. That’s the power of Sapiom.