Getting Data In

Bad request error from C# API

wdthem
Explorer

I am attempting to connect to our Splunk API instance via the C# API to do a search and I am receiving a 400 Bad Request error and I am not having much luck debugging it.

I am following the Search example in the C# demo solution from Splunk.

The code looks like this:

searchTerm = string.Format("--search=\"{0}\"", searchTerm);
var jobs = SplunkService.GetJobs();
var job = jobs.Create(searchTerm);

...and searchTerm equals:

index=prodabtest sourcetype=nlogab e=Development f=Sample v=SampleControl

I receive the Bad Request on the last line with it tries to create the job.

This appears to be the same thing the example solution is doing, so I am a bit at a loss.

Thanks!

-Will

Tags (2)
0 Karma
1 Solution

ywu_splunk
Splunk Employee
Splunk Employee

Code passes "--search=..." to API as search string. That is not correct. You would need to pass "searchTerm" directly to the API, for example, "search index=_internal * | head 100".

"--search=..." is used in the example as a command line argument marker. It is removed and the extracted search term is passed to API.

View solution in original post

ywu_splunk
Splunk Employee
Splunk Employee

Code passes "--search=..." to API as search string. That is not correct. You would need to pass "searchTerm" directly to the API, for example, "search index=_internal * | head 100".

"--search=..." is used in the example as a command line argument marker. It is removed and the extracted search term is passed to API.

wdthem
Explorer

Quick update: I am able to connect to the API instance via Curl, so I am pretty sure all is well with connection and authentication - just unsure of why the API code is throwing the 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!

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 ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...