Splunk Search

Showing errors when try to send data to splunk cloud in reactjs but it's working fine with postman and curl in terminal?

Herry
New Member

Using fecth in reactjs:

fetch('https://[SUBDOMAIN].splunkcloud.com:8088/services/collector/event/1.0', {
method: 'POST',

headers: {
'Access-Control-Allow-Origin': 'application/json',
'Access-Control-Allow-Credentials': 'true',
'Access-Control-Allow-Methods': 'OPTIONS, GET, POST',
'Access-Control-Allow-Headers':
'Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control',
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Splunk [TOKEN]'
},
body: JSON.stringify({
sourcetype: '_json',
index: 'main',
host: 'mydata2',
event: { foo: 'bar3', b: ['value1_3', 'value1_4'] }
})
})
.then((res) => res.json())
.then((json) => {
// eslint-disable-next-line no-console
console.log('json---->', json);
});

Screenshot-from-2021-10-11-17-55-45-png-1600×900-.png


Using splunk-logging in reactjs:

 import * as SplunkLogging from 'splunk-logging';

 


const SplunkLogger = SplunkLogging.Logger;

const config = {
token: [TOKEN],
url: '[URL]:8088'
};

// eslint-disable-next-line no-var
const Logger = new SplunkLogger(config);

Logger.requestOptions.strictSSL = true;

// eslint-disable-next-line no-var
const payload = {
// Message can be anything; doesn't have to be an object
message: {
temperature: '70F',
chickenCount: 500
}
};

console.info('Sending payload', payload);
Logger.send(payload, function (err, resp, body) {
// If successful, body will be { text: 'Success', code: 0 }
console.info('Response from Splunk', body);
});

 

'.png





Labels (1)
0 Karma

sxmudem
New Member

Is there any luck for above error.I am also seeing same error

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

Data Management Digest – May 2026

Welcome to the May 2026 edition of Data Management Digest!   As your trusted partner in data innovation, the ...