How to work with DELETE request and X-Auth-Token - http-headers

I want DELETE operation be allowed only after authentication/authorization process. I tried to do a DELETE operation passing an X-Auth-Token, but I got this: The status of this operation is: 400 Some error occurred!
{"error":"BadRequest","description":"Orion accepts no payload for GET/DELETE requests. HTTP header Content-Type is thus forbidden"}
I did this with GET request, without problem, but it is not working for DELETE.
headers = {'X-Auth-Token': token}
s = Session()
request = Request('DELETE', DELETE_URL + entity_id, headers=headers)
prepped = request.prepare()
del prepped.headers['Content-Length']
r = s.send(prepped)

Problem solved, like #fgalan told in previous comments. A fix was made at PEP Proxy Wilma, as it can be seen here

You should remove the content-type header as suggested by the error message.

Related

How to solve HTTPError: 400 Client Error: Bad Request for URL inRobot Frame work

I know there are many similar kinds of questions available but none of them worked.
Can someone tell me if there is any kind of syntax error for the Testcase below
Create Token
Create Session testsession ${baseUrl} verify=true
${body}= create dictionary clientId=unittest.cc.client clientSecret=RyDQ$xxxxxRtv
${header}= create dictionary Content-Type=application/json
${resp}= POST On Session testsession ${reqUri} json=${body} headers=${header} params=${ApiKeyParameter}
${source data}= Evaluate json.loads("""${resp.content}""") json
${token}= Set Variable ${source data['accessToken']}
#No errors Uptill this much - Bearer token creation was successful after that getting error while using it
${header}= create dictionary Authorization=${tpre} ${token} Content-Type=application/json cookies=ss-id=KF84fFy4txxxxxxxxx76i; ss-pid=StDTDxxxxxxxxxxxxn7r
${body}= get file API/data.txt
log to console ${header}
${resp}= post on session testsession /orders json=${body} headers=${header}
log to console ${resp.status_code}
The problem is every time I run the test I am getting a 400 error. Below is the Python code provided by POSTMAN and the screenshots of the headers used. Now I am not sure of how to get the HOST header in my python or maybe robot framework.
Please let me know if any additional details are needed. I am not sure of headers in the URL formation while get or post request is done
Is there any way to find that out?
import requests
import JSON
url = "https://domain:10001/orders?format=json"
payload = json.dumps({ Can ignore this part
})
headers = {
'Authorization': 'Bearer xxx',
'Content-Type': 'application/json',
'Cookie': 'ss-id=xxx; ss-pid=xxx'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
If you all ever come across this kind of issue don't forget to check the body of the JSON / XML you are sending.
Mine resolved as I was saving the dump JSON in a text file so while reading from the file my code was adding some extra spaces in front so I was getting a 400 error.
For further information try logging the Response Content it must show you the error message.

How do I respond to the Dropbox webhook challenge in Dark?

I want to respond to a Dropbox webhook using my Dark app (https://darklang.com/)
It says I need to set some headers to respond to the challenge (https://www.dropbox.com/developers/reference/webhooks)
How do I even set headers in the response?
The trick is twofold:
You need to set the correct headers. This is tricky in Dark, especially with headers that have a dash in the name
And, you need to pull the 'challenge' out of the URL parameters and then put that in the body of the request. Try this:
let body = request.queryParams.challenge
let headers = Dict::empty
|>Dict::set "Content-Type" "text/plain"
|>Dict::set "X-Content-Type-Options" "nosniff"
let response = Http::respondWithHeaders body headers 200
response

Use header in multiple calls in the same scenario in Karate

Having a feature with only one scenario with more than one http calls, I want to use the same host and headers for all calls. However, although I am able to set the url to apply for all calls, the header seems to only be applied in the first call and then reset. Does someone have any info on why this is happening and/or a suggestion on how to do it correctly (besides adding them in each call separately)?
Either by setting them in the Background or with a generic Given, url is used in both calls, but the header is only included in the first:
1)
Feature: sample
Background:
* header Content-Type = 'application/json'
* url http://localhost:8080
Scenario: do multiple calls
Given path /sample/
When method GET
Then status 200
Given path /sample2/
When method GET
Then status 200
2)
Feature: sample2
Given header Content-Type = 'application/json'
And url http://localhost:8080
Scenario: do multiple calls
Given path /sample/
When method GET
Then status 200
Given path /sample2/
When method GET
Then status 200
You really really should read the documentation: https://github.com/intuit/karate#configure-headers
Just do:
Background:
* configure headers = { 'Content-Type': 'application/json' }
And there are many more options, just read the docs. Note that you typically never need to set the Content-Type because Karate does that automatically based on the request body.
I had the same problem. It was fixed when I added the "Header" informations I always use to the "karate-config.js".
var accessToken = karate.callSingle("classpath:helpers/authentication.feature").accessToken
karate.configure("headers",{Authorization: "Bearer " + accessToken})

Send DELETE request to an API endpoint using Nestful Sinatra

I want to send a DELETE request to an external API endpoint in a controller of my Sinatra application using nestful gem. I want to delete an event by sending a DELETE request to an endpoint of TeamSnap API. I have defined the following route in controller:
delete '/events/:id' do
delete 'https://api.teamsnap.com/v3/events/76674685'
end
When the API endpoint is hit with delete action, I get the following error:
*** "Delete" argument "endpoint" needs to be a number
If I send a get request to the API endpoint, I get the correct response. The get request I am using is given below:
get '/events/:id' do
get 'https://api.teamsnap.com/v3/events/76674685'
end
Can anyone confirm how can we send the DELETE request in the controller and what I am missing?
Thanks in advance!
[Solved]: I sent a DELETE request through Nestful using the following commands:
delete '/events/:id' do
request = Nestful::Request.new(endpoint, options)
request.method = 'delete'
response = request.execute
end
In the above piece of code, endpoint is "https://api.teamsnap.com/v3/events/EVENT_ID" and options is a hash which contains "Content-Type" and "Authorization" headers.

Upload file to Solr with HttpClient and MultipartEntity

httpclient, httpmime 4.1.3
I am trying to upload a file through http to a remote server with no success.
Here's my code:
HttpPost method;
method = new HttpPost(solrUrl + "/extract");
method.getParams().setParameter("literal.id", fileId);
method.getParams().setBooleanParameter("commit", true);
MultipartEntity me = new MultipartEntity();
me.addPart("myfile", new InputStreamBody(doubleInput, contentType, fileId));
method.setEntity(me);
//method.setHeader("Content-Type", "multipart/form-data");
HttpClient httpClient = new DefaultHttpClient();
HttpResponse hr = httpClient.execute(method);
The server is Solr.
This is to replace a working bash script that calls curl like this,
curl http://localhost:8080/solr/update/extract?literal.id=bububu&commit=true -F myfile=#bububu.doc
If I try to set "Content-Type" "multipart/form-data", the receiving part says that there's no boundary (which is true):
HTTP Status 500 - the request was rejected because no multipart boundary was found
If I omit this header setting, the server issues an error description that, as far as I discovered, indicates that the content type was not multipart [2]:
HTTP Status 400. The request sent by the client was syntactically incorrect ([doc=null] missing required field: id).
This is related to [1] but I couldn't determine the answer from it. I was wondering,
I am in the same situation but didn't understand what to do. I was hoping that the MultipartEntity would tell the HttpPost object that it is multipart, form data and have some boundary, and I wouldnt set content type by myself. I didn't quite get how to provide boundaries to the entities - the MultipartEntity doesn't have a method like setBoundary. Or, how to get that randomly generated boundary to specify it in addHeader by myself - no getBoundary methor either...
[1] Problem with setting header "Content-Type" in uploading file with HttpClient4
[2] http://lucene.472066.n3.nabble.com/Updating-the-index-with-a-csv-file-td490013.html
I am suspicious of
method.getParams().setParameter("literal.id", fileId);
method.getParams().setBooleanParameter("commit", true);
In the first line, is fileId a string or file pointer (or something else)? I hope it is a string. As for the second line, you can rather set a normal parameter.
I am trying to tackle the HTTP Status 400. I dont know much Java (or is that .Net?)
http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#4xx_Client_Error