Get Group Invite Code
Retrieve the invite code for a WhatsApp group
Get Group Invite Code
Retrieve the invite code (the part of the invite link that is unique to the group) for a specific WhatsApp group. This code can be used to construct the full invite link.
Endpoint
GET /{sessionId}/groups/{groupId}/invite-code
Headers
Name | Type | Required | Description |
---|---|---|---|
Authorization | string | Yes | Bearer token for authentication |
Path Parameters
Parameter | Type | Required | Description |
---|---|---|---|
sessionId | string | Yes | The session ID |
groupId | string | Yes | The group ID |
Response
{
"success": true,
"inviteCode": "AbCdEfGhIjKlMnOpQrStUv"
}
Examples
curl -X GET "https://api.wasend.dev/{sessionId}/groups/{groupId}/invite-code" \
-H "Authorization: Bearer YOUR_API_KEY"
import { WasendClient } from '@wasend/core';
const client = new WasendClient({
apiKey: 'YOUR_API_KEY',
baseUrl: 'https://api.wasend.dev'
});
const sessionId = "yourSessionId";
const groupId = "yourGroupId";
// Get group invite code
const result = await client.getGroupInviteCode(sessionId, groupId);
// The SDK method getGroupInviteCode directly returns the code string based on API.md
// If the API actually wraps it in {success: true, inviteCode: "..."}, the SDK might need adjustment
// or this example should parse a potential object response.
// Assuming direct string for now as per API.md for the SDK method's direct return value.
console.log('Group invite code:', result);
const { WasendClient } = require('@wasend/core');
const client = new WasendClient({
apiKey: 'YOUR_API_KEY',
baseUrl: 'https://api.wasend.dev'
});
const sessionId = "yourSessionId";
const groupId = "yourGroupId";
// Get group invite code
client.getGroupInviteCode(sessionId, groupId)
.then(code => {
console.log('Group invite code:', code);
})
.catch(error => {
console.error('Error:', error);
});
from wasend import WasendClient
client = WasendClient(
api_key='YOUR_API_KEY',
base_url='https://api.wasend.dev'
)
session_id = "yourSessionId"
group_id = "yourGroupId"
# Get group invite code
# Assuming the SDK returns the code string directly
code = client.get_group_invite_code(
session_id=session_id,
group_id=group_id
)
print(f"Group invite code: {code}")
package main
import (
"fmt"
"log"
"github.com/wasenddev/wasend-sdk-go/wasendcore"
)
func StringPtr(s string) *string { return &s }
func main() {
client := wasendcore.NewWasendClient(&wasendcore.WasendConfig{
ApiKey: StringPtr("YOUR_API_KEY"),
BaseUrl: StringPtr("https://api.wasend.dev"),
})
sessionId := "yourSessionId"
groupId := "yourGroupId"
// Get group invite code
// API.md states this returns a string. The actual endpoint might return JSON: {"success": true, "inviteCode": "..."}
// The Go SDK for getGroupInviteCode returns (string, error)
code, err := client.GetGroupInviteCode(sessionId, groupId)
if err != nil {
log.Fatalf("Error getting group invite code: %v", err)
}
fmt.Printf("Group invite code: %s\n", code)
}
using Wasend.Core;
using System;
using System.Threading.Tasks;
public class Example
{
public static async Task Main(string[] args) // API.md states sync return string
{
var config = new WasendConfig
{
ApiKey = "YOUR_API_KEY"
};
var client = new WasendClient(config);
string sessionId = "yourSessionId";
string groupId = "yourGroupId";
// Get group invite code
// API.md states this returns a string. The actual endpoint might return JSON: {"success": true, "inviteCode": "..."}
// The .NET SDK for GetGroupInviteCode returns string
var code = client.GetGroupInviteCode(sessionId, groupId);
Console.WriteLine($"Group invite code: {code}");
}
}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
HttpClient httpClient = HttpClient.newHttpClient();
String sessionId = "yourSessionId";
String groupId = "yourGroupId";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.wasend.dev/" + sessionId + "/groups/" + groupId + "/invite-code"))
.header("Authorization", "Bearer YOUR_API_KEY")
.GET()
.build();
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
// Assuming the response is JSON: {"success": true, "inviteCode": "..."}
System.out.println("Response: " + response.body());
}
}
<?php
$sessionId = 'yourSessionId';
$groupId = 'yourGroupId';
$url = "https://api.wasend.dev/{$sessionId}/groups/{$groupId}/invite-code";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer YOUR_API_KEY'
]);
$response = curl_exec($ch);
curl_close($ch);
// Assuming the response is JSON: {"success": true, "inviteCode": "..."}
echo $response;
?>
require 'net/http';
require 'uri';
require 'json';
session_id = 'yourSessionId'
group_id = 'yourGroupId'
uri = URI("https://api.wasend.dev/#{session_id}/groups/#{group_id}/invite-code")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true # For HTTPS
request_obj = Net::HTTP::Get.new(uri.request_uri)
request_obj['Authorization'] = 'Bearer YOUR_API_KEY'
response = http.request(request_obj)
# Assuming the response is JSON: {"success": true, "inviteCode": "..."}
puts "Response: #{response.body}"
import Foundation
let sessionId = "yourSessionId"
let groupId = "yourGroupId"
let url = URL(string: "https://api.wasend.dev/\(sessionId)/groups/\(groupId)/invite-code")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue("Bearer YOUR_API_KEY", forHTTPHeaderField: "Authorization")
let task = URLSession.shared.dataTask(with: request) { data, response, error in
if let data = data, let responseString = String(data: data, encoding: .utf8) {
// Assuming the response is JSON: {"success": true, "inviteCode": "..."}
print("Response: \(responseString)")
}
}
task.resume()
use reqwest::Client;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::new();
let session_id = "yourSessionId";
let group_id = "yourGroupId";
let url = format!("https://api.wasend.dev/{}/groups/{}/invite-code", session_id, group_id);
let response_text = client
.get(&url)
.header("Authorization", "Bearer YOUR_API_KEY")
.send()
.await?
.text()
.await?;
// Assuming the response is JSON: {"success": true, "inviteCode": "..."}
println!("Response: {}", response_text);
Ok(())
}
Response Fields
If the API returns a JSON object:
Field | Type | Description |
---|---|---|
success | boolean | Whether the operation was successful |
inviteCode | string | The group invite code |
error | string | Optional. Error message if not successful |
If the API returns the invite code string directly (as suggested by SDK method signatures):
The response body will be a plain string containing the invite code.
Error Codes
Code | Description |
---|---|
400 | Bad Request - Invalid parameters |
401 | Unauthorized - Invalid or missing API key |
403 | Forbidden - Not authorized to get invite code |
404 | Not Found - Session or group not found |
429 | Too many requests - Rate limit exceeded |
500 | Internal server error |
Notes
- You must be an admin of the group to get its invite code.
- The invite code is part of the group invite link (e.g.,
https://chat.whatsapp.com/YOUR_INVITE_CODE
). - The invite code can be revoked by admins (see Revoke Group Invite Code).
- If the API returns a JSON response with
success: false
, anerror
field may be present with details.