# How to connect my api directly to kibana?

**URL:** <https://discuss.elastic.co/t/how-to-connect-my-api-directly-to-kibana/365971>\
**Category:** Kibana\
**Created:** [September 3, 2024, 2:13pm UTC](https://discuss.elastic.co/t/how-to-connect-my-api-directly-to-kibana/365971 "2024-09-03T14:13:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![OAJ](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/oaj/32/137265_2.png) [@OAJ](https://discuss.elastic.co/u/OAJ)\
**Post date:** [September 3, 2024, 2:13pm UTC](https://discuss.elastic.co/t/how-to-connect-my-api-directly-to-kibana/365971/1 "2024-09-03T14:13:05Z")

</div>

Hi, there I'm new to Kibana.

I was wondering if I have an API link such as `api.sampleapis.com/switch/games` how can I connect it to Kibana directly so that I may use it in my dashboard.

The only way I found is to upload it to Kibana is by converting the json into bulk data format for Elasticsearch then upload it using PowerShell, which works. But this means that every time there's a change in API I need to do same steps over and over again.

I want it to be automatic and instantly read the API from source.

Here is the code I've been using to upload locally from my laptop:

1. run json file

```auto
const axios = require("axios");
const fs = require("fs");

// Function to convert data into Elasticsearch bulk format
function convertToElasticsearchBulkFormat(data, indexName) {
  const bulkData = [];

  data.forEach((item) => {
    const docId = item.id;
    delete item.id;
    bulkData.push({ index: { _index: indexName, _id: docId } });
    bulkData.push(item);
  });

  return bulkData;
}

// Function to fetch data from API and convert it
async function fetchDataAndConvert(apiUrl, indexName) {
  try {
    const response = await axios.get(apiUrl);
    const data = response.data;

    const bulkFormatData = convertToElasticsearchBulkFormat(data, indexName);

    fs.writeFileSync(
      "bulk_data.json",
      bulkFormatData.map((line) => JSON.stringify(line)).join("\n")
    );
    console.log("Data successfully converted and saved to bulk_data.json");
  } catch (error) {
    console.error("Error fetching or converting data:", error);
  }
}

const apiUrl = "https://api.sampleapis.com/switch/games";
const indexName = "gametest";
fetchDataAndConvert(apiUrl, indexName);

```

1. Run PS commands for upload

```auto
$username = "elastic"

$password = "enter-your-pass"

$securePassword = ConvertTo-SecureString $password -AsPlainText -Force

$credential = New-Object System.Management.Automation.PSCredential ($username, $securePassword)

Invoke-RestMethod -Uri "https://localhost:9200/gametest/_bulk?pretty" -Method Post -ContentType 'application/x-ndjson' -InFile "bulk_data.json" -Credential $credential

```

I'm using version 8.15

Thanks in advance

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [September 3, 2024, 2:47pm UTC](https://discuss.elastic.co/t/how-to-connect-my-api-directly-to-kibana/365971/2 "2024-09-03T14:47:45Z")

</div>

From #Community Ecosystem to #Kibana

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [September 3, 2024, 2:49pm UTC](https://discuss.elastic.co/t/how-to-connect-my-api-directly-to-kibana/365971/3 "2024-09-03T14:49:42Z")

</div>

Hi @OAJ,

Welcome! To confirm, you're asking if you can access data from another API within a Kibana dashboard? Are you looking to visualize the data in a component in your dashboard?

---

<div class="post-metadata">

**Author:** ![OAJ](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/oaj/32/137265_2.png) [@OAJ](https://discuss.elastic.co/u/OAJ)\
**Post date:** [September 3, 2024, 5:09pm UTC](https://discuss.elastic.co/t/how-to-connect-my-api-directly-to-kibana/365971/4 "2024-09-03T17:09:45Z")

</div>

Hi @carly.richmond,  
Yes I would like to connect data from a given API to Kibana hence visualize it in dashboard

---

<div class="post-metadata">

**Author:** ![carly.richmond](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/carly.richmond/32/104935_2.png) [@carly.richmond](https://discuss.elastic.co/u/carly.richmond)\
**Post date:** [September 4, 2024, 9:35am UTC](https://discuss.elastic.co/t/how-to-connect-my-api-directly-to-kibana/365971/5 "2024-09-04T09:35:21Z")

</div>

Ok, is there a particular reason why you don't want to ingest the data into Elasticsearch to visualize the data, potentially using an approach such as the [Logstash HTTP plugin](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-http.html) or [one of the Elasticsearch language clients](https://www.elastic.co/guide/en/elasticsearch/client/index.html)? That is probably what I would recommend to make visualizing different cuts of the data, along with constraints such as performance, enrichment and archiving.

Another option could be to write a [Kibana plugin](https://www.elastic.co/guide/en/kibana/current/external-plugin-development.html),. As you would be connecting to an API outside of Elastic I would be mindful of the security and performance impact to Kibana in your code as covered in the [general](https://www.elastic.co/guide/en/kibana/current/security-best-practices.html) and [security](https://www.elastic.co/guide/en/kibana/current/security-best-practices.html) best practices.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 2, 2024, 9:36am UTC](https://discuss.elastic.co/t/how-to-connect-my-api-directly-to-kibana/365971/6 "2024-10-02T09:36:05Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
