Skip to main content

KBank User Management

This guide explains how to create and manage KBank users through the Villa Payment API.

API Base URLs

The Villa Payment API is available in two environments:

  • Development: https://shop.villamarket.com/api/payment3devapi
  • Production: https://shop.villamarket.com/api/payment3api

Replace {BASE_URL} in the examples below with the appropriate base URL for your environment.

Creating a User

To create a new KBank user:

curl -X POST {BASE_URL}/kbank/user \
-H "Authorization: YOUR_COGNITO_ID_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"phone": "+66812345678",
"first_name": "John",
"last_name": "Doe"
}'

Request Parameters

ParameterTypeDescription
emailstringUser's email address
phonestringUser's phone number
first_namestringUser's first name
last_namestringUser's last name

Response

{
"message": "User created successfully",
"user_id": "usr_1234567890"
}

Error Handling

The API uses standard HTTP status codes to indicate success or failure:

  • 200: Success
  • 400: Bad Request (missing required fields)
  • 401: Unauthorized
  • 403: Forbidden
  • 500: Internal Server Error

Example error response:

{
"error": {
"code": "missing_field",
"message": "Missing required field: email"
}
}

Best Practices

  1. Validate user data before submission
  2. Handle API errors gracefully
  3. Implement proper error logging
  4. Use idempotency keys for retries
  5. Keep user data secure and encrypted
  6. Follow data protection regulations
  7. Implement rate limiting for user creation

Testing

For testing user management:

  1. Use test email addresses
  2. Verify phone number format
  3. Test address validation
  4. Check error responses
  5. Validate update operations