v3 SDK

Our SDK documentation provides comprehensive guidance and examples for developers to seamlessly integrate our project's functionality into their applications.

Python

Requirements

Python >=3.7

Installation

pip install newscatcherapi-python-sdk==6.0.2
from pprint import pprint
from newscatcherapi_client import Newscatcher, ApiException

newscatcher = Newscatcher(
    api_key="API_KEY",
)

try:
    # [Get] Search By Author Request
    get_response = newscatcher.search.get(
        q="raises AND series A",
        search_in="title_content"
    )
    print(get_response)
except ApiException as e:
    print("Exception when calling AuthorsApi.get: %s\n" % e)
    pprint(e.body)
    if e.status == 422:
        pprint(e.body["detail"])
    pprint(e.headers)
    pprint(e.status)
    pprint(e.reason)
    pprint(e.round_trip_time)

C#

Frameworks supported

  • .NET Core >=1.0

  • .NET Framework >=4.6

  • Mono/Xamarin >=vNext

Installation

Using the .NET Core command-line interface (CLI) tools:

dotnet add package Newscatcherapi.Net

Using the NuGet Command Line Interface (CLI):

nuget install Newscatcherapi.Net

Using the Package Manager Console:

Install-Package Newscatcherapi.Net

From within Visual Studio:

  1. Open the Solution Explorer.

  2. Right-click on a project within your solution.

  3. Click on Manage NuGet Packages...

  4. Click on the Browse tab and search for "Newscatcherapi.Net".

  5. Click on the "Newscatcherapi.Net" package, select the appropriate version in the right-tab and click Install.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using Newscatcherapi.Net.Client;
using Newscatcherapi.Net.Model;

namespace Example
{
    public class GetExample
    {
        public static void Main()
        {
            NewscatcherClient client = new NewscatcherClient();
            // Configure API key authorization: apiKey
            client.SetApiKey("YOUR_API_KEY");

            var q = "raises AND series A";
            var searchIn = "title_content";

            try
            {
                // [Get] Search For Articles Request
                SearchGetResponse result = client.Search.Get(q, searchIn);
                Console.WriteLine(result);
            }
            catch (ApiException e)
            {
                Console.WriteLine("Exception when calling SearchApi.Get: " + e.Message);
                Console.WriteLine("Status Code: "+ e.ErrorCode);
                Console.WriteLine(e.StackTrace);
            }
            catch (ClientException e)
            {
                Console.WriteLine(e.Response.StatusCode);
                Console.WriteLine(e.Response.RawContent);
                Console.WriteLine(e.InnerException);
            }
        }
    }
}

Go

Installation

Add to your project:

go get github.com/konfig-dev/newscatcher-go-sdk
package main

import (
    "fmt"
    "os"
    newscatcherapi "github.com/konfig-dev/newscatcher-go-sdk"
)

func main() {
    configuration := newscatcherapi.NewConfiguration()
    configuration.SetApiKey("X_API_TOKEN")
    client := newscatcherapi.NewAPIClient(configuration)

    request := client.SearchApi.Get(
        "raises AND series A",
    )
    request.SearchIn(""title_content"")
    
    resp, httpRes, err := request.Execute()

    if err != nil {
        fmt.Fprintf(os.Stderr, "Error when calling `SearchApi.Get``: %v\n", err)
        fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", httpRes)
    }
    // response from `Get`: SearchGetResponse
    fmt.Fprintf(os.Stdout, "Response from `SearchApi.Get`: %v\n", resp)
    fmt.Fprintf(os.Stdout, "Response from `SearchGetResponse.Get.Status`: %v\n", *resp.Status)
    fmt.Fprintf(os.Stdout, "Response from `SearchGetResponse.Get.TotalHits`: %v\n", resp.TotalHits)
    fmt.Fprintf(os.Stdout, "Response from `SearchGetResponse.Get.Page`: %v\n", resp.Page)
    fmt.Fprintf(os.Stdout, "Response from `SearchGetResponse.Get.TotalPages`: %v\n", resp.TotalPages)
    fmt.Fprintf(os.Stdout, "Response from `SearchGetResponse.Get.PageSize`: %v\n", resp.PageSize)
    fmt.Fprintf(os.Stdout, "Response from `SearchGetResponse.Get.Articles`: %v\n", resp.Articles)
    fmt.Fprintf(os.Stdout, "Response from `SearchGetResponse.Get.UserInput`: %v\n", resp.UserInput)
    fmt.Fprintf(os.Stdout, "Response from `SearchGetResponse.Get.ClustersCount`: %v\n", resp.ClustersCount)
    fmt.Fprintf(os.Stdout, "Response from `SearchGetResponse.Get.Clusters`: %v\n", resp.Clusters)
}

Java

Requirements

Building the API client library requires:

  1. Java 1.8+

  2. Maven (3.8.3+)/Gradle (7.2+)

If you are adding this library to an Android Application or Library:

  1. Android 8.0+ (API Level 26+)

Installation

To install the API client library to your local Maven repository, simply execute:

mvn clean install

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

mvn clean deploy

Refer to the OSSRH Guide for more information.

Maven users

Add this dependency to your project's POM:

<dependency>
  <groupId>com.konfigthis.newscatcherapi</groupId>
  <artifactId>newscatcherapi-java-sdk</artifactId>
  <version>6.0.1</version>
  <scope>compile</scope>
</dependency>

Gradle users

Add this dependency to your build.gradle:

// build.gradle
repositories {
  mavenCentral()
}

dependencies {
   implementation "com.konfigthis.newscatcherapi:newscatcherapi-java-sdk:6.0.1"
}

Android users

Make sure your build.gradle file as a minSdk version of at least 26:

// build.gradle
android {
    defaultConfig {
        minSdk 26
    }
}

Also make sure your library or application has internet permissions in your AndroidManifest.xml:

<!--AndroidManifest.xml-->
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <uses-permission android:name="android.permission.INTERNET"/>
</manifest>

Others

At first generate the JAR by executing:

mvn clean package

Then manually install the following JARs:

  • target/newscatcherapi-java-sdk-6.0.1.jar

  • target/lib/*.jar

import com.konfigthis.newscatcherapi.client.ApiClient;
import com.konfigthis.newscatcherapi.client.ApiException;
import com.konfigthis.newscatcherapi.client.ApiResponse;
import com.konfigthis.newscatcherapi.client.Newscatcher;
import com.konfigthis.newscatcherapi.client.Configuration;
import com.konfigthis.newscatcherapi.client.auth.*;
import com.konfigthis.newscatcherapi.client.model.*;
import com.konfigthis.newscatcherapi.client.api.SearchApi;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class Example {
  public static void main(String[] args) {
    Configuration configuration = new Configuration();
    configuration.host = "https://v3-api.newscatcherapi.com";
    
    configuration.apiKey  = "YOUR API KEY";
    Newscatcher client = new Newscatcher(configuration);
    String q = "raises AND series A";
    String searchIn = "title_content";
    Object predefinedSources = null;

  
    try {
      CSearchResponse result = client
              .search
              .get(q)
              .searchIn(searchIn)
              .execute();
      System.out.println(result);
      System.out.println(result.getStatus());
      System.out.println(result.getTotalHits());
      System.out.println(result.getPage());
      System.out.println(result.getTotalPages());
      System.out.println(result.getPageSize());
      System.out.println(result.getArticles());
      System.out.println(result.getUserInput());
      System.out.println(result.getClustersCount());
      System.out.println(result.getClusters());
    } catch (ApiException e) {
      System.err.println("Exception when calling SearchApi#get");
      System.err.println("Status code: " + e.getStatusCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}

Typescript

Installation

npm

npm i newscatcherapi-typescript-sdk

pnpm

pnpm i newscatcherapi-typescript-sdk

yarn

yarn add newscatcherapi-typescript-sdk
import { Newscatcher } from "newscatcherapi-typescript-sdk";

const newscatcher = new Newscatcher({
  // Defining the base path is optional and defaults to https://v3-api.newscatcherapi.com
  // basePath: "https://v3-api.newscatcherapi.com",
  apiKey: "API_KEY",
});

const getResponse = await newscatcher.search.get({
  q: "raises AND series A",
  searchIn: "title_content",
  byParseDate: false,
  sortBy: "relevancy",
  page: 1,
  pageSize: 100,
});

Last updated