Wasend

Create Session

Create a new WhatsApp session

Create Session

Create a new WhatsApp session with your desired configuration.

Endpoint

POST /sessions

Headers

NameTypeRequiredDescription
AuthorizationstringYesBearer token for authentication
Content-TypestringYesMust be application/json

Request Body

{
  "sessionName": "string",
  "phoneNumber": "string",
  "enableAccountProtection": boolean,
  "enableMessageLogging": boolean,
  "enableWebhook": boolean,
  "webhookUrl": "string"
}

Request Fields

FieldTypeRequiredDescription
sessionNamestringYesName of the session
phoneNumberstringYesPhone number for the WhatsApp session
enableAccountProtectionbooleanNoEnable account protection features
enableMessageLoggingbooleanNoEnable message logging
enableWebhookbooleanNoEnable webhook notifications
webhookUrlstringYes*Webhook URL for notifications (required if enableWebhook is true)

Response

{
  "uniqueSessionId": "string",
  "sessionName": "string",
  "phoneNumber": "string",
  "status": "string",
  "createdAt": "string",
  "updatedAt": "string"
}

Example

curl -X POST "https://api.wasend.dev/sessions" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "sessionName": "My Business Account",
    "phoneNumber": "+1234567890",
    "enableAccountProtection": true,
    "enableMessageLogging": true,
    "enableWebhook": false
  }'
import { WasendClient } from '@wasend/core';

const client = new WasendClient({
  apiKey: 'YOUR_API_KEY',
  baseUrl: 'https://api.wasend.dev'
});

// Create a new session
const newSession = await client.createSession({
  sessionName: 'My Business Account',
  phoneNumber: '+1234567890',
  enableAccountProtection: true,
  enableMessageLogging: true,
  enableWebhook: false
});

console.log('Created session:', newSession);
const { WasendClient } = require('@wasend/core');

const client = new WasendClient({
  apiKey: 'YOUR_API_KEY',
  baseUrl: 'https://api.wasend.dev'
});

const newSession = await client.createSession({
  sessionName: 'My Business Account',
  phoneNumber: '+1234567890',
  enableAccountProtection: true,
  enableMessageLogging: true,
  enableWebhook: false
});

console.log('Created session:', newSession);
from wasend import WasendClient

client = WasendClient(
    api_key='YOUR_API_KEY',
    base_url='https://api.wasend.dev'
)

new_session = client.create_session({
    'sessionName': 'My Business Account',
    'phoneNumber': '+1234567890',
    'enableAccountProtection': True,
    'enableMessageLogging': True,
    'enableWebhook': False
})

print('Created session:', new_session)
package main

import (
	"fmt"
	"github.com/wasenddev/wasend-sdk-go/wasendcore"
)

func StringPtr(s string) *string    { return &s }
func Float64Ptr(f float64) *float64 { return &f }

func main() {
	client := wasendcore.NewWasendClient(&wasendcore.WasendConfig{
		ApiKey:  StringPtr("YOUR_API_KEY"),
		BaseUrl: StringPtr("https://api.wasend.dev"),
	})

	newSession := client.CreateSession(&wasendcore.SessionCreateRequest{
		SessionName:            StringPtr("My Business Account"),
		PhoneNumber:           StringPtr("+1234567890"),
		EnableAccountProtection: Float64Ptr(1),
		EnableMessageLogging:    Float64Ptr(1),
		EnableWebhook:          Float64Ptr(0),
	})

	fmt.Printf("Created session: %+v\n", newSession)
}
using Wasend.Core;

var config = new WasendConfig
{
    ApiKey = "your-api-key-here" // Required
    // BaseUrl and Timeout are optional and have default values
};

var client = new WasendClient(config);
var newSession = client.CreateSession(new SessionCreateRequest
{
    SessionName = "My Business Account",
    PhoneNumber = "+1234567890",
    EnableAccountProtection = true,
    EnableMessageLogging = true,
    EnableWebhook = false
});

Console.WriteLine($"Created session: {newSession}");
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;
import org.json.JSONObject;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();
        
        JSONObject requestBody = new JSONObject();
        requestBody.put("sessionName", "My Business Account");
        requestBody.put("phoneNumber", "+1234567890");
        requestBody.put("enableAccountProtection", true);
        requestBody.put("enableMessageLogging", true);
        requestBody.put("enableWebhook", false);

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.wasend.dev/sessions"))
            .header("Authorization", "Bearer YOUR_API_KEY")
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(requestBody.toString()))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println("Response: " + response.body());
    }
}
<?php
$ch = curl_init();

$data = [
    'sessionName' => 'My Business Account',
    'phoneNumber' => '+1234567890',
    'enableAccountProtection' => true,
    'enableMessageLogging' => true,
    'enableWebhook' => false
];

curl_setopt($ch, CURLOPT_URL, "https://api.wasend.dev/sessions");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Bearer YOUR_API_KEY",
    "Content-Type: application/json"
]);

$response = curl_exec($ch);
curl_close($ch);

echo "Response: " . $response;
require 'net/http'
require 'uri'
require 'json'

uri = URI('https://api.wasend.dev/sessions')
request = Net::HTTP::Post.new(uri)
request['Authorization'] = 'Bearer YOUR_API_KEY'
request['Content-Type'] = 'application/json'

request.body = {
  sessionName: 'My Business Account',
  phoneNumber: '+1234567890',
  enableAccountProtection: true,
  enableMessageLogging: true,
  enableWebhook: false
}.to_json

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
  http.request(request)
end

puts "Response: #{response.body}"
import Foundation

let url = URL(string: "https://api.wasend.dev/sessions")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer YOUR_API_KEY", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")

let body: [String: Any] = [
    "sessionName": "My Business Account",
    "phoneNumber": "+1234567890",
    "enableAccountProtection": true,
    "enableMessageLogging": true,
    "enableWebhook": false
]

request.httpBody = try? JSONSerialization.data(withJSONObject: body)

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print("Response: \(String(data: data, encoding: .utf8) ?? "")")
    }
}
task.resume()
use reqwest::header::{HeaderMap, HeaderValue, AUTHORIZATION, CONTENT_TYPE};
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut headers = HeaderMap::new();
    headers.insert(
        AUTHORIZATION,
        HeaderValue::from_str("Bearer YOUR_API_KEY")?
    );
    headers.insert(
        CONTENT_TYPE,
        HeaderValue::from_str("application/json")?
    );

    let client = reqwest::Client::new();
    let response = client
        .post("https://api.wasend.dev/sessions")
        .headers(headers)
        .json(&json!({
            "sessionName": "My Business Account",
            "phoneNumber": "+1234567890",
            "enableAccountProtection": true,
            "enableMessageLogging": true,
            "enableWebhook": false
        }))
        .send()
        .await?
        .text()
        .await?;

    println!("Response: {}", response);
    Ok(())
}

SDK Integration

The WASend SDKs provide a simple and consistent interface across all supported languages. Here's how to integrate them into your project:

TypeScript/JavaScript

# Using npm
npm install @wasend/core

# Using yarn
yarn add @wasend/core

Python

pip install wasend

.NET

dotnet add package Wasend.Core

Go

go get github.com/wasenddev/wasend-sdk-go

Integration Testing

The SDKs include integration tests that demonstrate proper usage. Here's an example of a typical session lifecycle:

  1. Create a new session
  2. Get QR code for authentication
  3. Get session information
  4. Start/restart the session
  5. Stop the session
  6. Delete the session

For detailed integration examples, refer to the SDK documentation and test files in each repository.

Response Fields

FieldTypeDescription
uniqueSessionIdstringUnique identifier for the session
sessionNamestringName of the session
phoneNumberstringPhone number associated with the session
statusstringCurrent status of the session
createdAtstringTimestamp when the session was created
updatedAtstringTimestamp when the session was last updated

Error Codes

CodeDescription
400Bad Request - Invalid parameters
401Unauthorized - Invalid or missing API key
409Conflict - Session with same name already exists
429Too many requests - Rate limit exceeded
500Internal server error

Notes

  • Session names must be unique
  • Phone numbers must be in international format
  • Account protection features help secure your WhatsApp account
  • Message logging can be enabled for debugging purposes
  • Webhook notifications require a valid webhook URL
  • The session will be in a CREATED state after creation
  • You need to scan the QR code to connect the session to WhatsApp