<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: REST API Access in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Could-anyone-spot-why-the-code-is-failing-to-create-a-search/m-p/543411#M9735</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;The issue was on how axios was dealing with its payload. Just needed to encode data for to be able to calculate content-length.&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;CM&lt;/P&gt;</description>
    <pubDate>Thu, 11 Mar 2021 15:36:44 GMT</pubDate>
    <dc:creator>ChintanaM</dc:creator>
    <dc:date>2021-03-11T15:36:44Z</dc:date>
    <item>
      <title>Could anyone spot why the code is failing to create a search with HTTP POST?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Could-anyone-spot-why-the-code-is-failing-to-create-a-search/m-p/543386#M9734</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;I am trying to initiate a search using Splunk cloud rest API. Using following code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;const accessToken = "--my-super-secret-token--";
const url = "https://company-installation.splunkcloud.com:8089/services/search/jobs";

try {
  const authHeaderValue = `Splunk ${accessToken}`;

  const config = {
    headers: {
      'Authorization': authHeaderValue
    },
    params: {
      'output_mode': 'json',
      'search':'search *'
    }
  };

  const res = await axios.post(url, config);

  return {
    statusCode: 200,
    body: JSON.stringify(res.data),
  };
  
} catch (e) {


  return {
    statusCode: 400,
    body: JSON.stringify(e),
  };
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When the code is executed I get a 401 at line &lt;STRONG&gt;const res = await axios.post(url, config);&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;My api token is valid and my IP address is whitelisted&lt;/P&gt;
&lt;P&gt;When axios.post is replaced with axios.get, I get list of searches back which also verifies token and IP address are good&lt;/P&gt;
&lt;P&gt;Could anyone spot why the code is failing to create a search with HTTP POST please?&lt;/P&gt;
&lt;P&gt;I am very new to Splunk REST API and any help is much appreciated&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 12:37:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Could-anyone-spot-why-the-code-is-failing-to-create-a-search/m-p/543386#M9734</guid>
      <dc:creator>ChintanaM</dc:creator>
      <dc:date>2022-08-30T12:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Access</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Could-anyone-spot-why-the-code-is-failing-to-create-a-search/m-p/543411#M9735</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;The issue was on how axios was dealing with its payload. Just needed to encode data for to be able to calculate content-length.&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;CM&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 15:36:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Could-anyone-spot-why-the-code-is-failing-to-create-a-search/m-p/543411#M9735</guid>
      <dc:creator>ChintanaM</dc:creator>
      <dc:date>2021-03-11T15:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Access</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Could-anyone-spot-why-the-code-is-failing-to-create-a-search/m-p/611252#M10742</link>
      <description>&lt;P class="lia-align-left"&gt;Hi &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/230800"&gt;@ChintanaM&lt;/a&gt;,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm also new to splunk and I faced to a problem, maybe you can help me. Does you search param works fine? I'm also trying to search with axios post request but I'm getting 26mb of data. It seems that my search parameter doesn't work and my request return all the data that exists.&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 08:24:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Could-anyone-spot-why-the-code-is-failing-to-create-a-search/m-p/611252#M10742</guid>
      <dc:creator>arsen_ye</dc:creator>
      <dc:date>2022-08-30T08:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: REST API Access</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Could-anyone-spot-why-the-code-is-failing-to-create-a-search/m-p/636776#M10985</link>
      <description>&lt;P&gt;Could you expand on this with what you had changed?&amp;nbsp; I have no idea what you meant by encode data.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2023 20:33:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Could-anyone-spot-why-the-code-is-failing-to-create-a-search/m-p/636776#M10985</guid>
      <dc:creator>Pat</dc:creator>
      <dc:date>2023-03-30T20:33:31Z</dc:date>
    </item>
  </channel>
</rss>

