> ## Documentation Index
> Fetch the complete documentation index at: https://docs.propaga.mx/llms.txt
> Use this file to discover all available pages before exploring further.

# Send User Confirmation

> This webhook is used to send the user data to your system when the user finish the registration process

## Webhook Endpoint

You should configure your webhook endpoint to receive POST requests from Propaga. The webhook will send the user data in JSON format.
Please contact us to set up the webhook.

## Payload Structure

Here's an example of the webhook payload you'll receive:

```json theme={null}
{
  "id": "563249dd-6fc6-4d85-8ac7-42114ba8cf80",
  "userId": "671f75a4-f145-4f4b-82ff-4eaf0fd1e5aa",
  "externalId": "123456789",
  "status": "validated",
}
```

### Payload Fields

| Field        | Type   | Description                          |
| ------------ | ------ | ------------------------------------ |
| `id`         | String | The ID of the user confirmation.     |
| `userId`     | String | The Propaga's ID of the user.        |
| `externalId` | String | The ID of the user in your system.   |
| `status`     | String | The status of the user confirmation. |

## Handling the Webhook

Here's an example of how to handle the webhook in different programming languages:

<CodeGroup>
  ```javascript JavaScript theme={null}
  app.post('/webhook/user-confirmation', async (req, res) => {
    try {
      const userConfirmation = req.body;
      
      // Process the user confirmation data
      await processUserConfirmation(userConfirmation);
      
      // Respond with success
      res.status(200).json({ status: 'success' });
    } catch (error) {
      console.error('Error processing user confirmation:', error);
      res.status(500).json({ status: 'error', message: error.message });
    }
  });

  async function processUserConfirmation(userConfirmation) {
    // Validate the user confirmation
    console.log(`Processing user confirmation: ${userConfirmation.id}`);
    console.log(`Status: ${userConfirmation.status}`);
    
    // Process each transaction
    console.log(`User ID: ${userConfirmation.userId}`);
    console.log(`External ID: ${userConfirmation.externalId}`);
  }
  ```

  ```python Python theme={null}
  from flask import Flask, request, jsonify

  app = Flask(__name__)

  @app.route('/webhook/user-confirmation', methods=['POST'])
  def handle_user_confirmation():
      try:
          userConfirmation = request.json
          
          # Process the user confirmation data
          process_user_confirmation(userConfirmation)
          
          return jsonify({'status': 'success'}), 200
      except Exception as e:
          print(f'Error processing user confirmation: {str(e)}')
          return jsonify({'status': 'error', 'message': str(e)}), 500

  def process_user_confirmation(userConfirmation):
      # Validate the transfer amount
      print(f"Processing transfer: {conciliation['referenceNumber']}")
      print(f"Total amount: {conciliation['transferedAmount']}")
      
      # Process each transaction
      for transaction in conciliation['transactions']:
          print(f"Processing transaction: {transaction['transactionId']}")
          # Your transaction processing logic here
  ```
</CodeGroup>

## Best Practices

1. **Verify the Webhook Source**: Implement security measures to verify that the webhook is coming from Propaga.

2. **Implement Idempotency**: Store the `referenceNumber` to avoid processing the same conciliation multiple times.

3. **Handle Errors Gracefully**: Implement proper error handling and logging to track any issues with webhook processing.

4. **Respond Quickly**: Your webhook endpoint should respond as quickly as possible. If processing takes time, handle it asynchronously.

5. **Validate Data**: Always validate the incoming data before processing it.
