Http get method for Splunk saved search using access token - request

What would be the correct HTTP get request call syntax to fetch saved search data from Splunk if we're accessing it through an access token?
My curl command is working but http.get is not.
curl command:
#os.system('curl -H "Authorization: Bearer <token>"
<baseurl>:8089/services/search/jobs/export --data search="savedsearch abc_backup_status" -d output_mode=csv')
request call ::::
BASE_URL = '<baseurl>:8089/services/search/jobs/export'
data = {"search":"savedsearch abc_backup_status"}
headers = {'Authorization': "Bearer <token>"}
auth_response = requests.get(BASE_URL, headers=headers, data = data, verify=False)
this is giving 400 errors.

The curl options -d OR --data imply a POST method by default.
From: https://man7.org/linux/man-pages/man1/curl.1.html
-d, --data <data>
(HTTP MQTT) Sends the specified data in a POST request to
the HTTP server, in the same way that a browser does when
a user has filled in an HTML form and presses the submit
button. This will cause curl to pass the data to the
server using the content-type application/x-www-form-
urlencoded. Compare to -F, --form.
It is interesting that Splunk Docs claim that search/jobs/export takes a GET, but you're creating a job to immediately export, which feels like a POST type of operation.
Also I notice that your search starts with the savedsearch command, if that's a regularly scheduled savedsearch, you may want to GET saved/searches/{name}/history to get the last execution SID, followed either by the results or events endpoint of that already executed job, instead of a new search.... but that's a use case question

Related

how can i build the authentication using symfony 6 and raeact js?

In my App i don t need a registration feature so i added a user in the database manually ,Actually I tried with the LexiJWTAuthenticationBundle i followed the documentation but unfortunately when I use the cURL to send a request i get the following error
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
<hr>
<address>Apache/2.4.52 (Win64) OpenSSL/1.1.1m PHP/8.1.4 Server at localhost Port 443</address>
</body></html>```
**the cURL request is
curl -X POST -H "Content-Type: application/json" https://localhost/api/check_login --data '{"email":"johndoe#gmail.fr","password":"test"}' -k
Moreover frankly i m confused about the logic of the bundle so im worried if i need a controller or not .
However in the frontENd i m using reactJS i just sent a post request using axios
but when i hit submit in the network when i inspect i get
{
"code": 401,
"message": "JWT Token not found"
}
I think documentation is only showing an example. Not sure if that works out of the box because after installing it, I haven't seen a new Controller to handle the login_check route. In fact, ask to add the route manually, without referring a resource.
To generate a Token from a user, in a controller you will need to instantiate Jwt.
// src/Controller/AuthController.PHP
use App\Entity\User;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
class AuthController
{
private JWTTokenManagerInterface $jwt;
public function __construct(JWTTokenManagerInterface $jwt)
{
$this->jwt = $jwt;
}
#[Route(path: '/token', name: 'api_auth_token')]
public function login(Request $request): Response
{
// Code to retrieve your user
// [...]
// User must extends UserInterface for Lexik to work properly
$token = $this->jwt->create($user);
// return the token
}
This code will show you how to create the token, but not to login. You will have to check your authentication flow.
Side note: Don´t confuse hashing the password with generating a token. You will need to do both things separately
I recommend you to look for the service you need by exploring autowirng:
php bin/console debug:autowiring jwt

OSRM: Getting output in Flatbuffers format for route service

I hosted osrm v5.24.0 on my local machine using a dataset preprocessed with CH (Contraction Hierarchies) pipeline. And I need to get the output of route response in flatbuffers format. But I couldn't find the correct query for that.
API Documentation reference: http://project-osrm.org/docs/v5.24.0/api/#requests
osrm request
Query I am using (Postman):
/route/v1/driving/73.14568712144677,-0.6875788801118562;73.13504135080412,-0.682499947378062?overview=full&alternatives=false&steps=false&geometries=geojson&format=flatbuffers
Result I get:
{
"message": "Query string malformed close to position 156",
"code": "InvalidQuery"
}
This is resolved. Following is the correct get request to get the response in flatbuffers format.
Get Request:
/route/v1/driving/73.14568712144677,-0.6875788801118562;73.13504135080412,-0.682499947378062.flatbuffers?overview=full&alternatives=false&steps=false&geometries=geojson

Flink REST API POST error while trying to start a new job using the uploaded jar

I am trying to hit the /jars/:jarid/run endpoint to start a Flink job as follows after reading up this SO post -
curl -k -v -X POST -H "Content-Type: application/json" --data '
{
"programArgsList": [
"--runner",
"FlinkRunner",
"--inputTopicName",
"inputTopicNameValue",
"--Argument",
"Value",
"--streaming",
"true"]
}
' http://<JobManager-hostname>:<port>/jars/MyApplication.jar/run
I get the following error when I try the above command -
{"errors":["Internal server error.","<Exception on server side:\norg.apache.flink.client.program.ProgramInvocationException: The main method
caused an error: Argument 'FlinkRunner' does not begin with '--'\n\tat
org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:546)\n\tat
org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:421)\n\tat
org.apache.flink.client.program.OptimizerPlanEnvironment.getOptimizedPlan(OptimizerPlanEnvironment.java:83)\n\tat
org.apache.flink.client.program.PackagedProgramUtils.createJobGraph(PackagedProgramUtils.java:80)
Argument 'FlinkRunner' does not begin with '--' leads me to think that argument values are not being provided correctly in my example. I understand that the Flink documentation provides the JSON schema definition and not the sample request in the REST API docs. What is the correct way to provide argument values? My example is following what the accepted solution suggested in this post.
The following POST request worked for me so I am documenting it here -
curl -k -v -X POST -H "Content-Type: application/json" --data '
{
"programArgsList": [
"--runner=FlinkRunner",
"--inputTopicName=inputTopicNameValue",
"--Argument=Value",
"--streaming=true"]
}
' http://<JobManager-hostname>:<port>/jars/MyApplication.jar/run

Angular $http.post returns 404 error

I am using angular JS to send some data to Payment Gateway.
Syntax for curl to send data as per documentation is:
curl https://www.mybank.co.uk/3dsecure
-H "Content-type: application/x-www-form-urlencoded"
-X POST
-d 'TermUrl=https://www.yourmerchantsite.co.uk/3DSecureConfirmation&PaReq=value-of-oneTime3DsToken&MD=merchantdatavalue'
However when I am doing it in Angular :
$http({
method: 'POST',
url: 'url',
headers: {'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'text/html'
},
data: $.param({TermUrl: obj.TermUrl ,Pareq: obj.Pareq }),
})
I am getting error
Possibly unhandled rejection: {"data":"<html><head><title>400 Bad
Request</title></head><body><h1>Bad Request</h1></body>
</html>","status":400,"config":
{"method":"POST","transformRequest":[null],"transformResponse":
[null],"jsonpCallbackParam":"callback","url":"payement gatway
url","headers":{"Content-Type":"application/x-www-form-urlencoded",
"Accept":"text/html,application/xhtml+xml"},"data":"TermUrl=url&Pare
q=value"},"statusText":"Bad Request","xhrStatus":"complete"}
Kindly suggest how to proceed with this one ?
First of all, you are experiencing a 400 Bad Request (https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400) and not a 404 Not Found.
It usually means that you are not sending the right data to the server and the API is expecting some specific parameters (from the body usually).
Check the API, look at every parameter required from it - their types and how they should be sent (body param? query string? etc...).
You can use your browser network tab or tools like Postman to see what you are actually sending to the server and if it matches what the server is expecting you to send.
Check out 3D Secure's API reference, you should get back a detailed error code beside the http status code:
https://developer.paysafe.com/en/3d-secure/api/#/introduction/error-summary/common-errors
It should be easily debuggable.

not reading the file when it was sent by postman

I have a problem with the sending of „Post” by postman
The request is constructed in this way:
my request
When I add various headers, I receive always the response „no data”.
When I send the file by the website, on which I tried to send the request, I receive always the returnable file – sending exacly the same file which I sent by postman.
The Problem is that when I don't send the file from the website, I receive the request „no file” and even as I send the request from postman without the file, I receive the request „no data”
So how can i send the file ?
request headers
The field containing the file has a name, and it's not "Content-Disposition." Check the web site HTML, see what the name of the field is, and enter it as the name of the File field in Postman. Note that the file field name appears in the request body, not the headers. It will look something like this:
------WebKitFormBoundaryzp81ydREocuBHzYN
Content-Disposition: form-data; name="datafile"; filename="0041e2b.jpg"
Content-Type: image/jpeg
In this case the field name is "datafile."

Resources