Code Examples

Implementation examples for popular languages and frameworks

Use these samples as a starting point for backend ingestion, mobile integrations, content sync jobs, or editorial automation pipelines.

Replace These Placeholders

  • YOUR_PROVIDER_ID with your provider ID
  • YOUR_API_KEY with your live API key
  • Adjust category_id, q, and limit as needed

1. cURL

curl -X GET "https://www.presswireindia.com/api/v1/news/releases?category_id=6&q=insurance&limit=20" \
  -H "X-Provider-Id: YOUR_PROVIDER_ID" \
  -H "Authorization: ApiKey YOUR_API_KEY" \
  -H "Accept: application/json"

2. PHP

<?php
$url = 'https://www.presswireindia.com/api/v1/news/releases?category_id=6&q=insurance&limit=20';

$headers = [
    'X-Provider-Id: YOUR_PROVIDER_ID',
    'Authorization: ApiKey YOUR_API_KEY',
    'Accept: application/json',
];

$ch = curl_init($url);
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_TIMEOUT => 15,
]);

$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
curl_close($ch);

$data = json_decode($response, true);

if ($statusCode === 200) {
    foreach ($data['items'] as $item) {
        echo $item['title'] . PHP_EOL;
    }
} else {
    echo $data['error']['message'] ?? 'Unknown API error';
}

3. ASP.NET / C#

using System.Net.Http.Headers;
using System.Text.Json;

var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-Provider-Id", "YOUR_PROVIDER_ID");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("ApiKey", "YOUR_API_KEY");

var url = "https://www.presswireindia.com/api/v1/news/releases?category_id=6&q=insurance&limit=20";
var response = await client.GetAsync(url);
var body = await response.Content.ReadAsStringAsync();

if (response.IsSuccessStatusCode)
{
    using var document = JsonDocument.Parse(body);
    foreach (var item in document.RootElement.GetProperty("items").EnumerateArray())
    {
        Console.WriteLine(item.GetProperty("title").GetString());
    }
}
else
{
    Console.WriteLine(body);
}

4. Python

import requests

url = "https://www.presswireindia.com/api/v1/news/releases"
params = {
    "category_id": 6,
    "q": "insurance",
    "limit": 20,
}
headers = {
    "X-Provider-Id": "YOUR_PROVIDER_ID",
    "Authorization": "ApiKey YOUR_API_KEY",
    "Accept": "application/json",
}

response = requests.get(url, params=params, headers=headers, timeout=15)
data = response.json()

if response.status_code == 200:
    for item in data["items"]:
        print(item["title"])
else:
    print(data["error"]["message"])

5. Flutter / Dart

import 'dart:convert';
import 'package:http/http.dart' as http;

Future<void> fetchPressReleases() async {
  final uri = Uri.parse('https://www.presswireindia.com/api/v1/news/releases').replace(queryParameters: {
    'category_id': '6',
    'q': 'insurance',
    'limit': '20',
  });

  final response = await http.get(
    uri,
    headers: {
      'X-Provider-Id': 'YOUR_PROVIDER_ID',
      'Authorization': 'ApiKey YOUR_API_KEY',
      'Accept': 'application/json',
    },
  );

  final data = jsonDecode(response.body) as Map<String, dynamic>;

  if (response.statusCode == 200) {
    final items = data['items'] as List<dynamic>;
    for (final item in items) {
      print(item['title']);
    }
  } else {
    print(data['error']['message']);
  }
}

6. Node.js

const url = new URL('https://www.presswireindia.com/api/v1/news/releases');
url.searchParams.set('category_id', '6');
url.searchParams.set('q', 'insurance');
url.searchParams.set('limit', '20');

const response = await fetch(url, {
  headers: {
    'X-Provider-Id': 'YOUR_PROVIDER_ID',
    'Authorization': 'ApiKey YOUR_API_KEY',
    'Accept': 'application/json',
  },
});

const data = await response.json();

if (response.ok) {
  data.items.forEach((item) => {
    console.log(item.title);
  });
} else {
  console.error(data.error.message);
}

7. Java

HttpClient client = HttpClient.newHttpClient();

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://www.presswireindia.com/api/v1/news/releases?category_id=6&q=insurance&limit=20"))
    .header("X-Provider-Id", "YOUR_PROVIDER_ID")
    .header("Authorization", "ApiKey YOUR_API_KEY")
    .header("Accept", "application/json")
    .GET()
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());

Best Practice

  • Use server-side code whenever possible.
  • Persist cursors or sync timestamps in your own database.
  • Keep API keys in secret storage or environment variables.
  • Handle non-200 responses explicitly in your integration.