Skip to content

Latest commit

 

History

History
144 lines (99 loc) · 3.62 KB

signup-example-docs.md

File metadata and controls

144 lines (99 loc) · 3.62 KB

User Signup Example

This example demonstrates how to use the Zarban SDK to implement a user signup process. The example shows how to create a new user account by sending a signup request to the Zarban API.

Prerequisites

Before running this example, make sure you have:

  1. Installed the Zarban SDK:
pip install zarban
  1. Access to the Zarban API (test environment)

Code Example

import zarban.wallet.openapi_client as wallet


def signup_example():
    # Create and configure the Configuration object
    cfg = wallet.Configuration(
        host="https://testwapi.zarban.io"
    )

    # Create an instance of the ApiClient with the configuration
    api_client = wallet.ApiClient(configuration=cfg)

    # Create an instance of the AuthApi using the api_client
    auth_api = wallet.AuthApi(api_client)

    # Prepare the signup request data
    signup_request = wallet.SignUpRequest(
        email="[email protected]",
        password="yourSecuredPassword",
    )

    try:
        # Call the signup API
        api_response = auth_api.signup_with_email_and_password(signup_request)
        print("Confirmation link sent successfully!")
        print(f"Message: {api_response.messages}")

    except wallet.ApiException as e:
        print(f"Exception when calling auth_api->signup_with_email_and_password: {e}")
        print(f"Error message: {e.body}")

if __name__ == "__main__":
    signup_example()

Step-by-Step Explanation

  1. Import Required Modules

    import zarban.wallet.openapi_client as wallet

    These imports provide the necessary classes and functions to interact with the Zarban API.

  2. Configure the API Client

     cfg = wallet.Configuration(
         host="https://testwapi.zarban.io"
     )
     api_client = wallet.ApiClient(configuration=cfg)

    Creates a configuration object with the API endpoint and initializes the API client.

  3. Initialize the API Instance

     auth_api = wallet.AuthApi(api_client)

    Creates an instance of the AuthApi class using the configured client.

  4. Prepare Signup Request

     signup_request = wallet.SignUpRequest(
         email="[email protected]",
         password="yourSecuredPassword",
     )

    Creates a signup request object with user credentials.

  5. Make the API Call

     api_response = auth_api.signup_with_email_and_password(signup_request)

    Sends the signup request to the API and handles the response.

Response Handling

The example includes error handling using try/except blocks:

  • On success: Prints a confirmation message and the response messages
  • On failure: Catches ApiException and prints the error details

Expected Output

On successful signup:

Confirmation link sent successful!
Message: [Confirmation email details...]

On error:

Exception when calling DefaultApi->auth_signup_post: [Error details]
Error message: [Detailed error message]

Important Notes

  1. Replace "[email protected]" and "yourSecuredPassword" with actual user credentials
  2. The example uses the test API endpoint (testwapi.zarban.io). For production use, update the host accordingly
  3. Ensure proper password security practices when implementing in production
  4. The API will send a confirmation email to the provided email address

Error Handling

Common errors that might occur:

  • Invalid email format
  • Password doesn't meet security requirements
  • Email already registered
  • Network connectivity issues
  • API server errors

See Also