Dear all,
I am trying to initiate a search using Splunk cloud rest API. Using following code
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),
};
}
When the code is executed I get a 401 at line const res = await axios.post(url, config);
My api token is valid and my IP address is whitelisted
When axios.post is replaced with axios.get, I get list of searches back which also verifies token and IP address are good
Could anyone spot why the code is failing to create a search with HTTP POST please?
I am very new to Splunk REST API and any help is much appreciated
Hi all,
The issue was on how axios was dealing with its payload. Just needed to encode data for to be able to calculate content-length.
Cheers
CM
Hi all,
The issue was on how axios was dealing with its payload. Just needed to encode data for to be able to calculate content-length.
Cheers
CM