Sharmo SDK Quick Start

Sharmo provides official SDKs for several programming languages to help you interact with our API more efficiently. This guide helps you get started quickly with our SDKs.

Overview

Our SDKs provide the following benefits:

Currently, we offer SDKs for:

JavaScript SDK

Installation

Install the JavaScript SDK with npm:

npm
npm install @sharmo/sdk

Or with yarn:

yarn
yarn add @sharmo/sdk

Basic Usage

JavaScript
// Import the SDK
import { SharmoClient } from '@sharmo/sdk';

// Initialize the client
const client = new SharmoClient({
  apiKey: 'your_api_key',
  environment: 'production' // Use 'sandbox' for testing
});

// Fetch properties
async function getProperties() {
  try {
    const properties = await client.properties.list({
      limit: 10,
      status: 'active'
    });
    
    console.log(`Found ${properties.length} properties`);
    
    // Work with the data
    properties.forEach(property => {
      console.log(`${property.address}: $${property.price}`);
    });
    
    return properties;
  } catch (error) {
    console.error('Error fetching properties:', error);
  }
}

// Call the function
getProperties();

TypeScript Support

Our JavaScript SDK includes TypeScript type definitions, providing auto-completion and type safety:

TypeScript
import { SharmoClient, Property, PropertyStatus } from '@sharmo/sdk';

const client = new SharmoClient({
  apiKey: 'your_api_key'
});

async function getActiveProperties(): Promise {
  try {
    const properties = await client.properties.list({
      status: PropertyStatus.ACTIVE,
      city: 'New York',
      minPrice: 100000,
      maxPrice: 500000
    });
    
    return properties;
  } catch (error) {
    console.error('Error fetching properties:', error);
    return [];
  }
}

Python SDK

Installation

Install the Python SDK with pip:

pip
pip install sharmo-sdk

Basic Usage

Python
from sharmo import Client

# Initialize the client
client = Client(api_key="your_api_key", environment="production")

# Fetch properties
def get_properties():
    try:
        properties = client.properties.list(
            limit=10,
            status="active"
        )
        
        print(f"Found {len(properties)} properties")
        
        # Work with the data
        for property in properties:
            print(f"{property.address}: ${property.price}")
        
        return properties
    except Exception as e:
        print(f"Error fetching properties: {e}")

# Call the function
properties = get_properties()

Java SDK

Installation

Add the Java SDK to your Maven project:

Maven
<dependency>
    <groupId>io.sharmo</groupId>
    <artifactId>sharmo-sdk</artifactId>
    <version>1.0.0</version>
</dependency>

Or with Gradle:

Gradle
implementation 'io.sharmo:sharmo-sdk:1.0.0'

Basic Usage

Java
import io.sharmo.sdk.SharmoClient;
import io.sharmo.sdk.models.Property;
import io.sharmo.sdk.exceptions.SharmoApiException;

import java.util.List;

public class SharmoExample {
    public static void main(String[] args) {
        // Initialize the client
        SharmoClient client = new SharmoClient.Builder()
            .apiKey("your_api_key")
            .environment("production") // Use "sandbox" for testing
            .build();
            
        try {
            // Fetch properties
            List properties = client.properties()
                .list()
                .status("active")
                .limit(10)
                .execute();
                
            System.out.println("Found " + properties.size() + " properties");
            
            // Work with the data
            for (Property property : properties) {
                System.out.println(property.getAddress() + ": $" + property.getPrice());
            }
        } catch (SharmoApiException e) {
            System.err.println("Error fetching properties: " + e.getMessage());
        }
    }
}

Common Tasks

Authentication

All SDKs support both API key and OAuth authentication:

JavaScript - OAuth
// OAuth authentication
const client = new SharmoClient({
  clientId: 'your_client_id',
  clientSecret: 'your_client_secret',
  redirectUri: 'https://your-app.com/callback',
  environment: 'production'
});

// Generate authorization URL
const authUrl = client.auth.getAuthorizationUrl({
  scope: ['read:properties', 'write:tokens']
});

// Later, exchange code for token
const tokens = await client.auth.exchangeCodeForToken(code);

// Now the client is authenticated
const userProfile = await client.users.getProfile();

Pagination

All SDKs provide built-in pagination support:

Python - Pagination
# Manual pagination
page1 = client.properties.list(limit=20, page=1)
page2 = client.properties.list(limit=20, page=2)

# Automatic pagination (iterator)
all_properties = []
for property in client.properties.iterate_all(limit=20):
    all_properties.append(property)
    # Process each property

# Get total count
total = client.properties.count(status="active")

Error Handling

All SDKs provide consistent error handling:

Java - Error Handling
try {
    client.tokens().transfer()
        .tokenId("tok_12345")
        .toAddress("0xabcdef...")
        .amount(5.5)
        .execute();
} catch (SharmoApiException e) {
    if (e.getStatusCode() == 401) {
        // Handle authentication error
        System.err.println("Authentication failed: " + e.getMessage());
    } else if (e.getStatusCode() == 429) {
        // Handle rate limit
        long retryAfter = e.getRetryAfter();
        System.err.println("Rate limited, retry after " + retryAfter + " seconds");
    } else {
        // Handle other errors
        System.err.println("API error: " + e.getMessage());
        System.err.println("Error code: " + e.getErrorCode());
    }
} catch (SharmoNetworkException e) {
    // Handle network errors
    System.err.println("Network error: " + e.getMessage());
}

Troubleshooting

Enable Debug Logging

All SDKs support debug logging for troubleshooting:

JavaScript - Debug Logging
const client = new SharmoClient({
  apiKey: 'your_api_key',
  debug: true // Enable debug logging
});
Python - Debug Logging
import logging

# Configure logging
logging.basicConfig(level=logging.DEBUG)

# Create client with debug enabled
client = Client(api_key="your_api_key", debug=True)

Common Issues

Issue Solution
Authentication failures Verify your API key or OAuth credentials and ensure they have the required permissions
Rate limiting Implement exponential backoff, batch operations, or cache responses to reduce API calls
Network timeouts Check your network connection and adjust timeout settings in the SDK configuration
SDK version compatibility Ensure you're using the latest SDK version compatible with your API version

Getting Help

If you're still experiencing issues: