API Publica Servicios Basicos

En el siguiente doumento se detallan los endpoints de la API publica de servicios basicos como agua luz y gas. El cual permite cargar y obtener la deuda de dichos servicios para viviendas y unidades.

Puedes descargar la API para Postman aqui.

El listado de los proveedores de servicios soportados lo puedes encontrar aqui.

URL BASE:

https://utilityservice.bolka.cl:8668/api/v1

/client

GET

Descripción

Recupera una lista de clientes.

Encabezados de solicitud

x-api-key (requerido): La clave de API para la autenticación.

Parámetros de consulta

id, provider (opcionales), en el caso de no proporcionarlos

la respuesta sera completa sin filtrado. Proveedores ['abastible', 'enel', 'metrogas', 'aguas_andinas', 'gasco', 'cge', 'chilquinta', 'nueva_atacama']

Respuesta

200 OK: Devuelve una matriz de clientes.

401 Unauthorized: Si la clave de API no es válida.

Ejemplo de solicitud

GET /api/v1/client

Headers:

x-api-key: tu-clave-de-api

Request:

https://utilityservice.bolka.cl:8668/api/v1/client?provider=abastible&id=ElSY0uZqgpxQeZk82ALdaz0ym0wr8QIbLMZg1nGG8dqpl6JdXt
https://utilityservice.bolka.cl:8668/api/v1/client?provider=abastible
https://utilityservice.bolka.cl:8668/api/v1/client?id=ElSY0uZqgpxQeZk82ALdaz0ym0wr8QIbLMZg1nGG8dqpl6JdXt
https://utilityservice.bolka.cl:8668/api/v1/client

Ejemplo de respuesta

Status: 200 OK

Body:


        {
            "id": "ElSY0uZqgpxQeZk82ALdaz0ym0wr8QIbLMZg1nGG8dqpl",
            "date": "2023-12-18T03:00:00.000Z",
            "client_number": "45676",
            "provider": "abastible",
            "api_key": "pZsZlHygRnq44FMSqCfNFbzMptRe9TR0rs",
            "deuda": 23560,
            "deuda_date": "2023-12-18T03:00:00.000Z",
            "days_difference": 0,
            "status": "ok"
        }
            

Ejemplos de codigo


              import requests
              
              url = 'https://utilityservice.bolka.cl:8668/api/v1/client'
              headers = {'x-api-key': 'tu-clave-de-api'}
              
              response = requests.get(url, headers=headers)
              
              print(response.json())
                

              fetch('https://utilityservice.bolka.cl:8668/api/v1/client', {
                headers: {
                  'x-api-key': 'tu-clave-de-api'
                }
              })
                .then(response => response.json())
                .then(data => console.log(data));
                

    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    
    public class Main {
    public static void main(String[] args) {
        try {
            URL url = new URL("https://utilityservice.bolka.cl:8668/api/v1/client");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setRequestProperty("x-api-key", "tu-clave-de-api");
        
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String inputLine;
            StringBuilder content = new StringBuilder();
            while ((inputLine = in.readLine()) != null) {
                content.append(inputLine);
            }
            in.close();
        
            System.out.println(content.toString());
        } catch (Exception e) {
        e.printStackTrace();
        }
    }
    }
                

        url="https://utilityservice.bolka.cl:8668/api/v1/client"
        api_key="tu-clave-de-api"
        
        curl -X GET -H "x-api-key: $api_key" $url
                

                   array(
                      'header' => "x-api-key: $api_key",
                      'method' => 'GET'
                      )
                  );
              
                  $context = stream_context_create($options);
                  $response = file_get_contents($url, false, $context);
              
                  if ($response === false) {
                      echo "Error fetching data.";
                  } else {
                      $data = json_decode($response);
                      print_r($data);
                  }
                  ?>
                

        const https = require('https');

        const url = 'https://utilityservice.bolka.cl:8668/api/v1/client';
        const apiKey = 'tu-clave-de-api';
        
        const options = {
            headers: {
            'x-api-key': apiKey
            }
        };

        https.get(url, options, (response) => {
            let data = '';
          
            response.on('data', (chunk) => {
              data += chunk;
            });
          
            response.on('end', () => {
              const jsonData = JSON.parse(data);
              console.log(jsonData);
            });
          }).on('error', (error) => {
            console.error(error);
          });
                

POST

Descripción

Crea o actualiza un cliente.

Encabezados de solicitud

x-api-key (requerido): La clave de API para la autenticación.

Cuerpo de la solicitud (x-www-form-urlencoded)

client_number (requerido): El numero de cliente asociado al proveedor.

provider (requerido): El proveedor del servicio.

['abastible', 'enel', 'metrogas', 'aguas_andinas', 'gasco', 'cge', 'chilquinta', 'nueva_atacama']

Respuesta

201 Created: Devuelve el numero de cliente, id, proveedor, marca de tiempo y un mensaje de éxito.

400 Bad Request: Valid Providers (abastible, enel, metrogas, aguas_andinas, gasco, cge, chilquinta, nueva_atacama)

400 Bad Request: Si el cuerpo de la solicitud no es válido.

401 Unauthorized: Si la clave de API no es válida.

Ejemplo de solicitud

POST /api/v1/client

Headers:

x-api-key: tu-clave-de-api

Body: x-wwww-form-urlencoded


            {
            "client_number": 2345,
            "provider": "abastible"
            }
            

Request:

https://utilityservice.bolka.cl:8668/api/v1/client

Ejemplo de respuesta

Status: 201 Created

Body:

{
    "client_number": 2345,            
    "id": ElSY0uZqgpxQeZk82ALdaz0ym0wr8QIbLMZg1nGG8dqp,
    "provider": "abastible",
    "timestamp": "2022-01-01T12:00:00Z",
    "message": "Client created or updated"
}

Ejemplos de codigo


        import requests

        url = 'https://utilityservice.bolka.cl:8668/api/v1/client'
        api_key = 'tu-clave-de-api'
        data = {'client_number': 'xxxx', 'provider': 'abastible'}
        
        response = requests.post(url, headers={'x-api-key': api_key, 'Content-Type': 'application/x-www-form-urlencoded'}, data=data)
        
        print(response.json())
            

        fetch('https://utilityservice.bolka.cl:8668/api/v1/client', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
                'x-api-key': 'tu-clave-de-api'
            },
            body: new URLSearchParams({ client_number: 'xxxx', provider: 'abastible' }).toString()
        })
        .then(response => response.json())
        .then(data => console.log(data));
            

import java.net.HttpURLConnection;
import java.net.URL;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
    try {
        URL url = new URL("https://utilityservice.bolka.cl:8668/api/v1/client");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        conn.setRequestProperty("x-api-key", "tu-clave-de-api");
        conn.setDoOutput(true);

        String data = "client_number=xxxx&provider=abastible";

        OutputStream os = conn.getOutputStream();
        os.write(data.getBytes());
        os.flush();

        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String inputLine;
        StringBuilder content = new StringBuilder();
        while ((inputLine = in.readLine()) != null) {
        content.append(inputLine);
        }
        in.close();

        System.out.println(content.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
    }
}
            

url="https://utilityservice.bolka.cl:8668/api/v1/client"
api_key="tu-clave-de-api"
data="client_number=xxxx&provider=abastible"

curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -H "x-api-key: $api_key" -d "$data" $url
            

const https = require('https');

const url = 'https://utilityservice.bolka.cl:8668/api/v1/client';
const apiKey = 'tu-clave-de-api';
const data = JSON.stringify({ client_number: 'xxxx', provider: 'abastible' });

const options = {
    method: 'POST',
    headers: {
    'Content-Type': 'application/json',
    'x-api-key': apiKey
    }
};

const req = https.request(url, options, (res) => {
    let responseData = '';

    res.on('data', (chunk) => {
    responseData += chunk;
    });

    res.on('end', () => {
    console.log(JSON.parse(responseData));
    });
});

req.write(data);
req.end();
            

    const https = require('https');
    const querystring = require('querystring');

    const url = 'https://utilityservice.bolka.cl:8668/api/v1/client';
    const apiKey = 'tu-clave-de-api';
    const data = querystring.stringify({ client_number: 'xxxx', provider: 'abastible' });
    
    const options = {
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'x-api-key': apiKey
        }
    };
    
    const req = https.request(url, options, (res) => {
        let responseData = '';
    
        res.on('data', (chunk) => {
        responseData += chunk;
        });
    
        res.on('end', () => {
        console.log(JSON.parse(responseData));
        });
    });
    
    req.write(data);
    req.end();
            

DELETE

Descripción

Elimina un cliente.

Encabezados de solicitud

x-api-key (requerido): La clave de API para la autenticación.

Cuerpo de la solicitud (x-www-form-urlencoded)

id [requerido]: id del cliente distinto a numero de cliente xxxx. puede ir junto con el proveedor o por si solo, pero debe ir id o proveedor o ambos.

provider [requerido]: El proveedor del servicio. puede ir junto con id o por si solo, pero debe ir id o proveedor o ambos.

En el caso de que se envie solo el id, se eliminara el cliente con ese id, en el caso de que se envie solo el proveedor se eliminaran todas los clientes de ese proveedor. En el caso de ir ambos es redundante ya que se eliminara cliente con ese id y ese proveedor.

Respuesta

200 Created: Devuelve el ID, clave de API, marca de tiempo y un mensaje de éxito.

400 Bad Request: Si el cuerpo de la solicitud no es válido.

401 Unauthorized: Si la clave de API no es válida.

Ejemplo de solicitud

DELETE /api/v1/client

Headers:

x-api-key: tu-clave-de-api

Body: x-wwww-form-urlencoded


            {
            "id": T1iwZ6GxvZypGNfgxWRDlXhoFD0nUckzvj88R0FEyWNIxfwkMS,
            "provider": "abastible"
            }
            

Body: x-wwww-form-urlencoded


            {
            "id": T1iwZ6GxvZypGNfgxWRDlXhoFD0nUckzvj88R0FEyWNIxfwkMS,
            }
            

Body: x-wwww-form-urlencoded


            {
            "provider": "abastible"
            }
            

Request:

https://utilityservice.bolka.cl:8668/api/v1/client

Ejemplo de respuesta

Status: 200 OK

Body:

{
        "id": "T1iwZ6GxvZypGNfgxWRDlXhoFD0nUckzvj88R0FEy",
        "apiKey": "pZsZlHygRnqtZFMSqCfNFbzMptRe9TR0rs",
        "timestamp": "2023-12-22T22:21:21.558Z",
        "message": "Client deleted"
}

Ejemplos de codigo


    import requests

    import requests

    url = 'https://utilityservice.bolka.cl:8668/api/v1/client'
    api_key = 'tu-clave-de-api'
    data = {'id': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'provider': 'abastible'}

    response = requests.delete(url, headers={'x-api-key': api_key, 'Content-Type': 'application/x-www-form-urlencoded'}, data=data)

    print(response.json())
            

    fetch('https://utilityservice.bolka.cl:8668/api/v1/client', {
        method: 'DELETE',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'x-api-key': 'tu-clave-de-api'
        },
        body: new URLSearchParams({ id: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', provider: 'abastible' }).toString()
    })
    .then(response => response.json())
    .then(data => console.log(data));
            

import java.net.HttpURLConnection;
import java.net.URL;
import java.io.OutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
    try {
        URL url = new URL("https://utilityservice.bolka.cl:8668/api/v1/client");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("DELETE");
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        conn.setRequestProperty("x-api-key", "tu-clave-de-api");
        conn.setDoOutput(true);

        String data = "id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&provider=abastible";

        OutputStream os = conn.getOutputStream();
        os.write(data.getBytes());
        os.flush();

        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String inputLine;
        StringBuilder content = new StringBuilder();
        while ((inputLine = in.readLine()) != null) {
        content.append(inputLine);
        }
        in.close();

        System.out.println(content.toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
    }
}
            

url="https://utilityservice.bolka.cl:8668/api/v1/client"
api_key="tu-clave-de-api"
data="id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&provider=abastible"

curl -X DELETE -H "Content-Type: application/x-www-form-urlencoded" -H "x-api-key: $api_key" -d "$data" $url
            

const https = require('https');

const url = 'https://utilityservice.bolka.cl:8668/api/v1/client';
const apiKey = 'tu-clave-de-api';
const data = JSON.stringify({ id: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', provider: 'abastible' });

const options = {
    method: 'DELETE',
    headers: {
    'Content-Type': 'application/json',
    'x-api-key': apiKey
    }
};

const req = https.request(url, options, (res) => {
    let responseData = '';

    res.on('data', (chunk) => {
    responseData += chunk;
    });

    res.on('end', () => {
    console.log(JSON.parse(responseData));
    });
});

req.write(data);
req.end();
            

const https = require('https');
const querystring = require('querystring');

const url = 'https://utilityservice.bolka.cl:8668/api/v1/client';
const apiKey = 'tu-clave-de-api';
const data = querystring.stringify({ id: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', provider: 'abastible' });

const options = {
    method: 'DELETE',
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        'x-api-key': apiKey
    }
};

const req = https.request(url, options, (res) => {
    let responseData = '';

    res.on('data', (chunk) => {
        responseData += chunk;
    });

    res.on('end', () => {
        console.log(responseData);
    });
});

req.write(data);
req.end();
            


/clienthistory

GET

Descripción

Recupera el historial de consulta de deuda de un cliente especifico.

Encabezados de solicitud

x-api-key (requerido): La clave de API para la autenticación.

Respuesta

200 OK: Devuelve una matriz historicas de deudas de un cliente.

401 Unauthorized: Si la clave de API no es válida.

Ejemplo de solicitud

GET /api/v1/clienthistory/id_cliente

Headers:

x-api-key: tu-clave-de-api

Request:

https://utilityservice.bolka.cl:8668/api/v1/clienthistory/id_cliente

Ejemplo de respuesta

Status: 200 OK

Body:


        [{
            "id": "12345",
            "date": "2023-12-18T03:00:00.000Z",
            "client_id": "1Df4m6mHlvmUIlodw",
            "monto": 23560
        },
        {
            "id": "78901",
            "date": "2024-01-18T03:00:00.000Z",
            "client_id": "1Df4m6mHlvmUIlodw",
            "monto": 33270
        }]
            

Ejemplos de codigo


        import requests
        
        url = 'https://utilityservice.bolka.cl:8668/api/v1/clienthistory/id_cliente'
        headers = {'x-api-key': 'tu-clave-de-api'}
        
        response = requests.get(url, headers=headers)
        
        print(response.json())
                

        fetch('https://utilityservice.bolka.cl:8668/api/v1/clienthistory/id_cliente', {
        headers: {
            'x-api-key': 'tu-clave-de-api'
        }
        })
        .then(response => response.json())
        .then(data => console.log(data));
                

import java.net.HttpURLConnection;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
public static void main(String[] args) {
    try {
        URL url = new URL("https://utilityservice.bolka.cl:8668/api/v1/clienthistory/id_cliente");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("x-api-key", "tu-clave-de-api");
    
        BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String inputLine;
        StringBuilder content = new StringBuilder();
        while ((inputLine = in.readLine()) != null) {
            content.append(inputLine);
        }
        in.close();
    
        System.out.println(content.toString());
    } catch (Exception e) {
    e.printStackTrace();
    }
}
}
                

        url="https://utilityservice.bolka.cl:8668/api/v1/clienthistory/id_cliente"
        api_key="tu-clave-de-api"
        
        curl -X GET -H "x-api-key: $api_key" $url
                

                   array(
                      'header' => "x-api-key: $api_key",
                      'method' => 'GET'
                      )
                  );
              
                  $context = stream_context_create($options);
                  $response = file_get_contents($url, false, $context);
              
                  if ($response === false) {
                      echo "Error fetching data.";
                  } else {
                      $data = json_decode($response);
                      print_r($data);
                  }
                  ?>
                

    const https = require('https');

    const url = 'https://utilityservice.bolka.cl:8668/api/v1/clienthistory/id_cliente';
    const apiKey = 'tu-clave-de-api';
    
    const options = {
        headers: {
        'x-api-key': apiKey
        }
    };

    https.get(url, options, (response) => {
        let data = '';
        
        response.on('data', (chunk) => {
            data += chunk;
        });
        
        response.on('end', () => {
            const jsonData = JSON.parse(data);
            console.log(jsonData);
        });
        }).on('error', (error) => {
        console.error(error);
        });
                



/client/weird

GET

Descripción

Recupera una lista de clientes de los cuales no se ha podido obtener deuda probablemente por que los numeros de clientes asociados estan erroneos, y se recomienda la revision manual de estos clientes.

Encabezados de solicitud

x-api-key (requerido): La clave de API para la autenticación.

Parámetros de consulta

id, provider (opcionales), en el caso de no proporcionarlos

la respuesta sera completa sin filtrado. Proveedores ['abastible', 'enel', 'metrogas', 'aguas_andinas', 'gasco', 'cge', 'chilquinta', 'nueva_atacama']

Respuesta

200 OK: Devuelve una matriz de clientes.

401 Unauthorized: Si la clave de API no es válida.

Ejemplo de solicitud

GET /api/v1/client/weird

Headers:

x-api-key: tu-clave-de-api

Request:

https://utilityservice.bolka.cl:8668/api/v1/client/weird?provider=abastible&id=ElSY0uZqgpxQeZk82ALdaz0ym0wr8QIbLMZg1nGG8dqpl6JdXt
https://utilityservice.bolka.cl:8668/api/v1/client/weird?provider=abastible
https://utilityservice.bolka.cl:8668/api/v1/client/weird?id=ElSY0uZqgpxQeZk82ALdaz0ym0wr8QIbLMZg1nGG8dqpl6JdXt
https://utilityservice.bolka.cl:8668/api/v1/client/weird

Ejemplo de respuesta

Status: 200 OK

Body:


        {
            "id": "ElSY0uZqgpxQeZk82ALdaz0ym0wr8QIbLMZg1nGG8dqpl",
            "date": "2023-12-18T03:00:00.000Z",
            "client_number": "45676",
            "provider": "abastible",
            "api_key": "pZsZlHygRnq44FMSqCfNFbzMptRe9TR0rs",
            "deuda": null,
            "deuda_date": null,
            "days_difference": null,
            "status": "fail"
        }
            

Ejemplos de codigo


              import requests
              
              url = 'https://utilityservice.bolka.cl:8668/api/v1/client/weird'
              headers = {'x-api-key': 'tu-clave-de-api'}
              
              response = requests.get(url, headers=headers)
              
              print(response.json())
                

              fetch('https://utilityservice.bolka.cl:8668/api/v1/client/weird', {
                headers: {
                  'x-api-key': 'tu-clave-de-api'
                }
              })
                .then(response => response.json())
                .then(data => console.log(data));
                

    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    
    public class Main {
    public static void main(String[] args) {
        try {
            URL url = new URL("https://utilityservice.bolka.cl:8668/api/v1/client/weird");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setRequestProperty("x-api-key", "tu-clave-de-api");
        
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String inputLine;
            StringBuilder content = new StringBuilder();
            while ((inputLine = in.readLine()) != null) {
                content.append(inputLine);
            }
            in.close();
        
            System.out.println(content.toString());
        } catch (Exception e) {
        e.printStackTrace();
        }
    }
    }
                

        url="https://utilityservice.bolka.cl:8668/api/v1/client/weird"
        api_key="tu-clave-de-api"
        
        curl -X GET -H "x-api-key: $api_key" $url
                

                   array(
                      'header' => "x-api-key: $api_key",
                      'method' => 'GET'
                      )
                  );
              
                  $context = stream_context_create($options);
                  $response = file_get_contents($url, false, $context);
              
                  if ($response === false) {
                      echo "Error fetching data.";
                  } else {
                      $data = json_decode($response);
                      print_r($data);
                  }
                  ?>
                

        const https = require('https');

        const url = 'https://utilityservice.bolka.cl:8668/api/v1/client/weird';
        const apiKey = 'tu-clave-de-api';
        
        const options = {
            headers: {
            'x-api-key': apiKey
            }
        };

        https.get(url, options, (response) => {
            let data = '';
          
            response.on('data', (chunk) => {
              data += chunk;
            });
          
            response.on('end', () => {
              const jsonData = JSON.parse(data);
              console.log(jsonData);
            });
          }).on('error', (error) => {
            console.error(error);
          });