Loading...

Code Samples

Ready-to-Use Code Samples

Jumpstart your integration with TrendWave Connect using these practical code samples. All examples are production-ready and can be easily adapted to your specific use case.

Pro Tip

Replace YOUR_API_KEY with your actual API key from the Developer Dashboard to test these examples.

Authentication

Learn how to authenticate with the TrendWave Connect API using different programming languages.

JavaScript/Node.js Authentication

Using the official JavaScript SDK for authentication.

JavaScript const TWCClient = require('@trendwaveconnect/sdk');

// Initialize the client with your API key
const client = new TWCClient({
  apiKey: 'YOUR_API_KEY'
});

// Test authentication by fetching current user
async function testAuth() {
  try {
    const user = await client.users.getCurrent();
    console.log('Authenticated as:', user.name);
  } catch (error) {
    console.error('Authentication failed:', error.message);
  }
}

testAuth();
Python Authentication

Using the official Python SDK for authentication.

Python from trendwave_connect import TWCClient

# Initialize the client with your API key
client = TWCClient(api_key='YOUR_API_KEY')

# Test authentication by fetching current user
try:
  user = client.users.get_current()
  print(f"Authenticated as: {user.name}")
except Exception as e:
  print(f"Authentication failed: {e}")
PHP Authentication

Using the official PHP SDK for authentication.

PHP <?php
require_once 'vendor/autoload.php';

use TrendWaveConnect\TWCClient;

// Initialize the client with your API key
$client = new TWCClient([
  'api_key' => 'YOUR_API_KEY'
]);

// Test authentication by fetching current user
try {
  $user = $client->users->getCurrent();
  echo "Authenticated as: " . $user->name . "\n";
} catch (Exception $e) {
  echo "Authentication failed: " . $e->getMessage() . "\n";
}
?>
cURL Authentication

Using direct HTTP requests with cURL for authentication.

cURL # Test authentication by fetching current user
curl -X GET \
  https://api.trendwaveconnect.com/v1/users/me \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"

User Management

Examples for managing user accounts and profiles.

Create User Account

Create a new user account with the required information.

JavaScript async function createUser() {
  try {
    const newUser = await client.users.create({
      email: 'user@example.com',
      name: 'John Doe',
      password: 'securepassword123',
      role: 'developer'
    });
    console.log('User created:', newUser.id);
  } catch (error) {
    console.error('Failed to create user:', error.message);
  }
}
Python def create_user():
  try:
    new_user = client.users.create(
      email='user@example.com',
      name='John Doe',
      password='securepassword123',
      role='developer'
    )
    print(f"User created: {new_user.id}")
  except Exception as e:
    print(f"Failed to create user: {e}")

Project Management

Examples for creating and managing software development projects.

Create New Project

Create a new software development project with detailed specifications.

JavaScript async function createProject() {
  const projectData = {
    name: 'E-commerce Mobile App',
    description: 'Build a cross-platform mobile app for online shopping',
    type: 'mobile',
    technologies: ['React Native', 'Node.js', 'MongoDB'],
    budget: 50000,
    timeline: 90 // days
  };

  try {
    const project = await client.projects.create(projectData);
    console.log('Project created successfully:', project.id);
  } catch (error) {
    console.error('Failed to create project:', error.message);
  }
}
List User Projects

Retrieve a paginated list of projects for the authenticated user.

JavaScript async function listProjects() {
  try {
    const projects = await client.projects.list({
      limit: 10,
      offset: 0,
      status: 'active'
    });

    projects.data.forEach(project => {
      console.log(`${project.name} - ${project.status}`);
    });
  } catch (error) {
    console.error('Failed to fetch projects:', error.message);
  }
}

Advanced Examples

More complex integration scenarios and best practices.

Complete App Integration

A complete example showing user authentication, project creation, and file upload in a single workflow.

JavaScript const TWCClient = require('@trendwaveconnect/sdk');
const fs = require('fs');

class TWCIntegration {
  constructor(apiKey) {
    this.client = new TWCClient({ apiKey });
  }

  async createCompleteProject(projectData, files = []) {
    try {
      // 1. Create project
      const project = await this.client.projects.create(projectData);
      console.log('Project created:', project.id);

      // 2. Upload files
      for (const filePath of files) {
        const file = fs.createReadStream(filePath);
        const upload = await this.client.files.upload(file, {
          projectId: project.id
        });
        console.log('File uploaded:', upload.filename);
      }

      return project;
    } catch (error) {
      console.error('Integration failed:', error.message);
      throw error;
    }
  }
}

// Usage
const integration = new TWCIntegration('YOUR_API_KEY');
integration.createCompleteProject({
  name: 'Complete Integration Example',
  description: 'Demonstrating full integration workflow'
}, ['./requirements.pdf', './design-mockup.png']);

Need More Examples?

Download our complete code samples repository with examples for all API endpoints and use cases.

View on GitHub Download Zip Now