Get Xml output in Httpie api - api

I need to have xml output fusing Httpie Api , this is the command i use :
http --verify no --auth='abc=:abc' \
GET https://example.com/api/v3/assets --pretty=format --format-options=xml.format:true,xml.indent:2
But i get only an output by default (table json)

Related

Test flask rest using curl. GET request with multiple query parameters

I'm using Flask framework to create the rest API. the code below is the rest I've wrote.
#app.route("/posts/v2/list_by_date", methods=['GET'])
def public_posts_list_by_date():
tracker_id = request.args.get('tracker_id')
advanced_filters = request.args.get('filters')
if advanced_filters:
advanced_filters = json.loads(advanced_filters)
else:
advanced_filters = {}
the 'filters' is an array of parameters such as start_date, limit, offset, end_date.
And I want to test the rest and I used this command to test it:
curl http://172.31.32.22:3100/posts/v2/list_by_date?tracker_id=6939&filters=start_date=2020-11-30T15:05:05&end_date=2021-01-20T15:05:05
The problem is I don't receive the parameters of the filters in flask, it always empty.
I tried the above command and many other curl commands But still, it doesn't send the filters parameters.
Use the parameter --data-urlencode to encode the data beforehand.
See also here.
curl -G "http://172.31.32.22:3100/posts/v2/list_by_date" \
--data-urlencode 'tracker_id=6939' \
--data-urlencode 'filters={"start_date":"2020-11-30T15:05:05", "end_date":"2021-01-20T15:05:05"}'

How to create a elasticsearch document document via URL(http)

I am new to elasticsearch and trying to find a way to create a document from url(http-API). I have tried below given options but none of them worked.
http://Myserver:9200/dilbert/user/3 -d '{ "name" : "Praveena" }
http://Myserver:9200/dilbert/user/3{ "name" : "Praveena" }
http://Myserver:9200/dilbert/user/3?pretty _create name=Praveena
I expect this to add a record. Here dilbert is Index name. user is type & 3 is id. This index only contains a single element called name.
First option should work, but you must explicitly set request type to PUT.
It seems to me that you use curl to insert data. If you send data to server with -d option, curl issues the POST request by default. But you specify id of document in URL, so Elasticsearch waits for PUT request (see official documentation). You can use POST requests only in case of automatic ID generation.
So your request may look as follows:
curl -X PUT http://Myserver:9200/dilbert/user/3 -d '{ "name" : "Praveena" }'

How to Display "title" and "displayvalue" from smart sheets using the cURL code shown below?

curl https://api.smartsheet.com/2.0/sheets/5848567060424580/columns/4140686686611332 -H "Authorization: Bearer 21txb6n2ajlf6dhsil8g3jxtdu"
^^^^That is the curl command i put into the terminal and when i do, i get this information poster below. The access token: 21txb6n2ajlf6dhsil8g3jxtdu & Sheet ID:5848567060424580. I want to get a curl command that only displays certain values instead of every single ID and formatting option in the columns from the Smartsheet. Any help would be useful thanks!
{"id":4140686686611332,"index":2,"title":"Column3","type":"TEXT_NUMBER","width":150}MAC-C02Q3C5MG8WP:~ jxs18$ curl https://api.smartsheet.com/2.0/sheets/584856724580 -H "Authorization: Bearer 21txb6n2ajlf6dhsil8g3jxtdu"
{"id":5848567060424580,"name":"JagTestSheet","version":1,"totalRowCount":3,"accessLevel":"EDITOR_SHARE","effectiveAttachmentOptions":["FILE","ONEDRIVE","GOOGLE_DRIVE","EVERNOTE","BOX_COM","EGNYTE","DROPBOX"],"ganttEnabled":false,"dependenciesEnabled":false,"resourceManagementEnabled":false,"cellImageUploadEnabled":true,"userSettings":{"criticalPathEnabled":false,"displaySummaryTasks":true},"permalink":"https://app.smartsheet.com/b/home?lx=PoM3LKb9HF6g_jsJ9JoWwg","createdAt":"2016-07-07T14:44:38Z","modifiedAt":"2016-07-07T15:22:53Z","columns":[{"id":1888886872926084,"index":0,"title":"Primary Column","type":"TEXT_NUMBER","primary":true,"width":150},{"id":6392486500296580,"index":1,"title":"Column2","type":"TEXT_NUMBER","width":150},{"id":4140686686611332,"index":2,"title":"Column3","type":"TEXT_NUMBER","width":150},{"id":8644286313981828,"index":3,"title":"Column4","type":"TEXT_NUMBER","width":150},{"id":481511989372804,"index":4,"title":"Column5","type":"TEXT_NUMBER","width":150},{"id":4985111616743300,"index":5,"title":"Column6","type":"TEXT_NUMBER","width":150}],"rows":[{"id":6858731183990660,"rowNumber":1,"expanded":true,"createdAt":"2016-07-07T15:22:53Z","modifiedAt":"2016-07-07T15:22:53Z","cells":[{"columnId":1888886872926084,"value":234.0,"displayValue":"234"},{"columnId":6392486500296580,"value":657.0,"displayValue":"657"},{"columnId":4140686686611332,"value":875.0,"displayValue":"875"},{"columnId":8644286313981828},{"columnId":481511989372804},{"columnId":4985111616743300}]},{"id":1229231649777540,"rowNumber":2,"siblingId":6858731183990660,"expanded":true,"createdAt":"2016-07-07T15:22:53Z","modifiedAt":"2016-07-07T15:22:53Z","cells":[{"columnId":1888886872926084,"value":564.0,"displayValue":"564"},{"columnId":6392486500296580,"value":546.0,"displayValue":"546"},{"columnId":4140686686611332,"value":453.0,"displayValue":"453"},{"columnId":8644286313981828},{"columnId":48151198937280MAC-C02Q3C5MG8WP:
You could consider piping the output into something like jsawk
to query the JSON response for what you are looking for from your cURL request.

splunk rest api search using R

I am trying to replicate the curl method mentioned in splunk rest api doc into R to perform search using R. Sorry, I won't be able provides details on the parameters to replicate. Hence attaching the link for reference.
curl -u admin:changeme -k https://localhost:8089/services/search/jobs -d search="search *"
This returns me a sid from curl. However when I try to replicate the same in R using httr it returns list of all search details. I have tried using both POST & GET in httr just in case. Below is sample code. Ideally below one should return me a sid. however it returns list of existing search details. Not sure what I am missing. I am new to Rcurl,httr. I tried curlperform as well, there also same. Seems, something is missing out. What exactly -d does in curl, is this the thing I am missing to replicate ?
response <- GET(splunk_server,path=search_job_export_endpoint,
config(ssl_verifyhost=FALSE, ssl_verifypeer=0),
authenticate(username, password),
query=list(search=urlencode(search_terms)),
verbose())
result <- read.table(text=content(response, as="text"), sep=",", header=TRUE,
stringsAsFactors=FALSE)

Bitfinex API Post Headers

I am having trouble properly setting headers for the Bitfinex API (https://www.bitfinex.com/pages/api). I have no trouble with the un-authenticated Get calls but I cannot get my authenticated Post calls working. An example call that I am working with is a Post to "/balances". I am hoping that somebody who uses the API can help me with what I am doing wrong. Here is some sample input and output (fake keys of course) that I am currently generating:
Private Key:
012345abcdef
API Key:
000111aaafff
Payload:
{"request": "/v1/balances","nonce": "1413737362"}
Base64 Payload:
e3JlcXVlc3Q6IC92MS9iYWxhbmNlcyxub25jZTogMTQxMzczNzM2Mn0=
Using the OpenSSL command:
echo -n 'e3JlcXVlc3Q6IC92MS9iYWxhbmNlcyxub25jZTogMTQxMzczNzM2Mn0=' | openssl dgst -hmac 012345abcdef -sha384 -hex
to get a signaure of
b18953370fad9bd5dd482d6ae07aeb96fdebd812e98cbf847f2d923bf66d1579eb31e10e1d79c7ae8405c54e28d0ae2a
So I get the Headers:
"X-BFX-APIKEY" "000111aaafff"
"X-BFX-PAYLOAD" "e3JlcXVlc3Q6IC92MS9iYWxhbmNlcyxub25jZTogMTQxMzczNzM2Mn0="
"X-BFX-SIGNATURE" "b18953370fad9bd5dd482d6ae07aeb96fdebd812e98cbf847f2d923bf66d1579eb31e10e1d79c7ae8405c54e28d0ae2a"
I have been trying everything I can think of and the responses I get from the API switch between "Invalid X-BFX-SIGNATURE." and "Invalid json.".
Where is the flaw in my process? I cannot see what I am doing incorrectly.
I was using a Unix system call to run the OpenSSL command. The result was returned in two lines, I was only reading the first line. Reading all lines until encountering and End of File solved the problem.