Skip to content

Request Examples for Common Programming Languages

The following examples send a JSON HTTP POST request to SonaActivateUser. They use cURL, Python, Node.js, C#/.NET, Java, and PHP.

This request enables sign-in for an existing user. Use a test account that you intend to activate. Replace the site name and API key before running an example. For XML SOAP requests, see Accessing the API using SOAP.

Request body

Save this JSON object in data.txt. Replace 1234 with the numeric ID of the user to activate.

{
  "api_key": "YOUR_API_KEY",
  "person_id": "1234"
}

CURL

curl -v -X POST --http1.1 -H "Content-Type: application/json; charset=utf-8" \
  --data-binary @data.txt -A "myCustomClient/202309011456" \
  https://yoursite.sona-systems.com/services/SonaAPI.svc/SonaActivateUser

Python

import requests

# Specify the file path and headers
file_path = 'data.txt'
headers = {
    'Content-Type': 'application/json; charset=utf-8',
    'User-Agent': 'myCustomClient/202309011456'
}

# Read the data from the file
with open(file_path, 'r') as file:
    data = file.read()

# Set the URL for the API endpoint
url = 'https://yoursite.sona-systems.com/services/SonaAPI.svc/SonaActivateUser'

# Send the POST request
response = requests.post(url, headers=headers, data=data)

# Output the response
print(response.status_code)
print(response.text)

Node.js

const fs = require('fs');
const axios = require('axios');

// Read the data from the file
const data = fs.readFileSync('data.txt', 'utf8');

// Set the headers
const headers = {
  'Content-Type': 'application/json; charset=utf-8',
  'User-Agent': 'myCustomClient/202309011456'
};

// Set the URL for the API endpoint
const url = 'https://yoursite.sona-systems.com/services/SonaAPI.svc/SonaActivateUser';

// Send the POST request
axios.post(url, data, { headers })
  .then(response => {
    console.log(response.status);
    console.log(response.data);
  })
  .catch(error => {
    console.error(error);
  });

C#/.NET

using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
  static async Task Main(string[] args)
  {
    string url = "https://yoursite.sona-systems.com/services/SonaAPI.svc/SonaActivateUser";
    string filePath = "data.txt";

    using HttpClient client = new HttpClient();
    client.DefaultRequestHeaders.Add("User-Agent", "myCustomClient/202309011456");

    string data = await File.ReadAllTextAsync(filePath);
    HttpContent content = new StringContent(data, System.Text.Encoding.UTF8, "application/json");

    HttpResponseMessage response = await client.PostAsync(url, content);
    string responseBody = await response.Content.ReadAsStringAsync();

    Console.WriteLine(response.StatusCode);
    Console.WriteLine(responseBody);
  }
}

Java

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

import okhttp3.*;

public class PostRequestExample {
  public static void main(String[] args) throws IOException {
    String url = "https://yoursite.sona-systems.com/services/SonaAPI.svc/SonaActivateUser";
    String filePath = "data.txt";

    OkHttpClient client = new OkHttpClient();

    String data = new String(Files.readAllBytes(Paths.get(filePath)));
    RequestBody body = RequestBody.create(data, MediaType.get("application/json; charset=utf-8"));

    Request request = new Request.Builder()
      .url(url)
      .post(body)
      .header("User-Agent", "myCustomClient/202309011456")
      .build();

    try (Response response = client.newCall(request).execute()) {
      System.out.println(response.code());
      System.out.println(response.body().string());
    }
  }
}

PHP

<?php

$url = 'https://yoursite.sona-systems.com/services/SonaAPI.svc/SonaActivateUser';
$file_path = 'data.txt';

$data = file_get_contents($file_path);

$options = [
  'http' => [
    'header' => [
      "Content-Type: application/json; charset=utf-8",
      "User-Agent: myCustomClient/202309011456"
    ],
    'method'  => 'POST',
    'content' => $data,
  ],
];

$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);

if ($response === FALSE) {
  die('Error');
}

echo $http_response_header[0] . "\n";
echo $response;
?>