API Documentation
  • List all APIs

API documentation list

Producer Service

Producer Events Service Rest API
https://producer.events.newtral.es/swagger

WebSocket Consumer Service

Consumer Events Service WebSocket API
https://consumer.events.newtral.es/swagger

Frequently Asked Questions

- What is API Producer Service ?

Producer Service API, is a Rest API that implements methods to produce the events necessary to send claim detection and matching requests.

- What is API Consumer Service ?

Consumer Service API, is a Websocket API to which the client subscribes to receive responses to claims detection and claim matching requests.

- What do you need to connect to both APIs?

You need an apiKey, each client receives its apiKey when the client registers.

How to send a request form the Producer Service?

Here are some examples:

Remember to change {ApiKey} to your Client apiKey in the following code.

- Request to claim-detection for a bunch of sentences
        
          curl -X 'POST' \
          'https://producer.events.newtral.es/claim-detection/statements' \
          -H 'accept: application/json' \
          -H 'tenant-api-key: {ApiKey}' \
          -H 'Content-Type: application/json' \
          -d '{
            "sentences": [
              "I like the sun.",
              "I like the moon."
            ]
          }'
        
        
- Request to find-claims in a text
        
          curl -X 'POST' \
          'https://producer.events.newtral.es/find-claims/resource/text' \
          -H 'accept: application/json' \
          -H 'tenant-api-key: {ApiKey}' \
          -H 'Content-Type: application/json' \
          -d '{
          "text": "I like the sun. I like the moon"
          }'
        
        
- Request to claim-detection in an article
        
          curl -X 'POST' \
          'https://producer.events.newtral.es/claim-detection/resource/article' \
          -H 'accept: application/json' \
          -H 'tenant-api-key: {ApiKey}' \
          -H 'Content-Type: application/json' \
          -d '{
          "url": "https://www.newtral.es/trump-app-asilo/20240915/"
          }'
        
        
- Request to find-claims in a tweet
        
          curl -X 'POST' \
          'https://producer.events.newtral.es/find-claims/resource/tweet' \
          -H 'accept: application/json' \
          -H 'tenant-api-key: {ApiKey}' \
          -H 'Content-Type: application/json' \
          -d '{
          "url": "https://x.com/jack/status/20"
          }'
        
        
- Request to claim-detection in an image
        
          curl -X 'POST' \
          'https://producer.events.newtral.es/claim-detection/resource/image' \
          -H 'accept: application/json' \
          -H 'tenant-api-key: {ApiKey}' \
          -H 'Content-Type: application/json' \
          -d '{
          "url": "https://jeroen.github.io/images/testocr.png"
          }'
        
        
- Request to find-claims in media content
        
          curl -X 'POST' \
          'https://producer.events.newtral.es/find-claims/resource/media' \
          -H 'accept: application/json' \
          -H 'tenant-api-key: {ApiKey}' \
          -H 'Content-Type: application/json' \
          -d '{
          "url": "https://videos.bannerbear.com/completed/movie-x62aV0wjn3pvwOYkm1.mp4"
          }'
        
        

How to subscribe to Consumer Service?

Here are some examples:

Remember to change {ApiKey} to your Client apiKey in the following code.

- Receive responses via websocket, example nodeJs
          
            /* Install dependencies */ 
            
            npm install "socket.io-client"

            /* Example */

            import { io } from "socket.io-client";

            const socket = io('wss://consumer.events.newtral.es');
            const ApiKey = {ApiKey};

            function subscribeToTopic() {
              if (!socket.connected) {
                socket.connect();
              }
              socket.emit('subscribeToTopic', { apiKey: ApiKey });
            }

            function unsubscribeToTopic() {
              socket.emit('unsubscribeAll', { apiKey: ApiKey });
            }

            socket.on('connect', () => {
              console.log('WebSocket connected');
              subscribeToTopic();
            });

            socket.on('reply-message', (message) => {
              console.log(message);
            });

            socket.on('subscribed', () => {
              console.log('Subscribed');
            });

            socket.on('unsubscribed', () => {
              socket.disconnect();
              console.log('Unsubscribed every consumer');
            });

          
        
- Receive responses via websocket, example Python
          
          /* Install dependencies */ 
            
          pip install "python-socketio[asyncio_client]"

          /* Example */

          import asyncio
          import socketio
          from typing import Any, Optional

          socket = socketio.AsyncClient()

          endpoint = "wss://consumer.events.newtral.es"
          apiKey = {ApiKey};

          
          async def connect():
            await socket.connect(endpoint, retry=True)
            await subscribe_topic()
            await socket.wait()


          async def subscribe_topic():
            await socket.emit("subscribeToTopic", {"apiKey": apiKey})


          async def unsubscribe_topic():
            await socket.emit("unsubscribeAll", {"apiKey": apiKey})


          @socket.event
            async def connected():
              print("connection established")


          @socket.event
            async def connect_error(data):
              print(f"The connection failed! {data}")


          @socket.event
            async def disconnect():
              print("I'm disconnected!")


          @socket.on("connect")
            async def suscribe():
              print("WebSocket connected")


          @socket.on("reply-message")
            async def messages(data):
              print(data)


          @socket.on("subscribed")
            async def subscribed(data):
              print(f'Subscribed to partition: {data["partition"]}')


          @socket.on("unsubscribed")
            async def unsubscribed(data: Optional[Any]):
              print("Unsubscribed every consumer")
              await socket.disconnect()


          if __name__ == "__main__":
            asyncio.run(connect())

          
        
- Receive responses via websocket, example PHP
          
          /* Install dependencies */ 
            
          composer require "elephantio/elephant.io"

          /* Example */

            require "vendor/autoload.php";

            use ElephantIO\Client as Elephant;


            $endpoint = "https://consumer.events.newtral.es";
            $apiKey =  {ApiKey};
            
            $client = Elephant::create($endpoint);
            $client->connect();
            $disconnect = false;
            echo "WebSocket connected\n";
            
            function subscribeToTopic($client, $apiKey)
            {
                $client->emit("subscribeToTopic", array("apiKey" => $apiKey));
            }
            
            function unsubscribeToTopic($client, $apiKey)
            {
                global $disconnect;
                $disconnect = true;
                $client->emit("unsubscribeAll", array("apiKey" => $apiKey));
            }
            
            subscribeToTopic($client, $apiKey);
            
            if ($packet = $client->wait("subscribed")) {
                echo ("Subscribed to " .  json_encode($packet->data));
            };
            
            while (($packet = $client->wait("reply-message")) && !$disconnect) {
                print_r($packet->data);
            };
            
            if ($packet = $client->wait("unsubscribed")) {
                $client->disconnect();
                echo "Unsubscribed every consumer\n";
            };
            

          
        
- Postman with Websocket APIs
You can test your Websocket APIs in Postman for the web Postman with Websocket