I am trying to pass the below API request in ROBOT framework
curl --request POST --url <API End Point> --form 'sourcefile=#/home/test.zip' --header "Authorization: <Bearer Token>"
Equivalent robot test case,
Sample Test Case
[Arguments] ${token}=default
Create Session mxesession ${mxe_host}
${accessToken}= Catenate Bearer ${token}
${data}= Create Dictionary sourcefile=/home/test.zip
${header}= Create Dictionary Authorization=${accessToken}
${response}= Post Request mxesession /v1/ml files=${data} headers=${header}
Should Be Equal As Strings ${response.status_code} 200
The above test case passed successfully when I execute it. But the file could not be processed by the application successfully, whereas it got processed successfully when passed via curl request directly. So, the point I am trying to say here there is no problem with file that I am passing here whereas the file passed to the application seems different via curl request command and robot framework test case.
Is the test case correct, especially the way I pass ‘sourcefile’ ?
Should I treat "#"/home/test.zip in this path differently in robot framework?
The link: Uploading files using multipart/form-data through REST API helped as suggested by Bryan Oakley.
Correct test case given below for reference:
Sample Test Case
[Arguments] ${token}=default
Create Session mxesession ${mxe_host}
${accessToken}= Catenate Bearer ${token}
${fileData}= Get Binary File /home/test.zip
&{fileParts}= Create Dictionary
Set To Dictionary ${fileParts} sourcefile=${fileData}
${response}= Post Request mxesession /v1/ml files=${fileParts} headers=${header}
Should Be Equal As Strings ${response.status_code} 200
The key lines are:
${fileData}= Get Binary File /home/test.zip
&{fileParts}= Create Dictionary
Set To Dictionary ${fileParts} sourcefile=${fileData}
Related
when triggering airflow via REST interface a json with the dag run parameters is provided.
How can i retrieve the json passed to the dag when triggering it?
Example
Having triggered a dag:
curl -X POST https://<airflow-url>/api/experimental/dags/<dag id>/dag_runs -H 'Content-Type: application/json' -d '{<some params encoded as json which I want to later retrieve>}'
I want to later retrieve the params encoded in the json via UI or via CLI.
Usecase: you locate a run that succeded and want to reproduce it.
Thanks in advance.
Heading
Normally we are able to play around with REST APIs related to application, since the application has method to let us create a JWT Token for authentication.
But we are unable to create an application, don’t understand where and we can get the token to authorize us to let us create an application.
Let me tell step by step how to do that
Open the file {AMS_INSTALL_DIR}/webapps/root/WEB-INF/web.xml and change the following line
<filter-class>io.antmedia.console.rest.AuthenticationFilter</filter-class>
with this one
<filter-class>io.antmedia.console.rest.JWTServerFilter</filter-class>
Open the file {AMS_INSTALL_DIR}/conf/red5.properties and change the following lines
server.jwtServerControlEnabled=false
server.jwtServerSecretKey=
with these ones. You can use any 32 character alphanumeric key.
server.jwtServerControlEnabled=false
server.jwtServerSecretKey=WRITE_YOUR_32_CHARACTER_SECRET_KEY
For our sample we use cizvvh7f6ys0w3x0s1gzg6c2qzpk0gb9 as secret key
Restart the service
sudo service antmedia restart
Generate JWT Token. There are plenty of libraries that you can do programmatically. The easiest way for now is using JWT Debugger. So our generated token is eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.tA6sZwz_MvD9Nocf3Xv_DXhJaeTNgfsHPlg3RHEoZRk
Make the call to Create Application as follows
curl -X POST -H "Content-Type: application/json" -H "Authorization:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.tA6sZwz_MvD9Nocf3Xv_DXhJaeTNgfsHPlg3RHEoZRk" "https://ovh36.antmedia.io:5443/rest/v2/applications/testapp"
The result should be something like {"success":true,"message":null,"dataId":null,"errorId":0}
The app should be generated in a couple of seconds. You can get the list of the applications with the following command
curl -X GET -H "Content-Type: application/json" -H "Authorization:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.tA6sZwz_MvD9Nocf3Xv_DXhJaeTNgfsHPlg3RHEoZRk" "https://ovh36.antmedia.io:5443/rest/v2/applications"
References:
Web Panel REST Methods
Web Panel REST Methods JWT Documentation
I am very new to testing / developing. I am currently testing a REST API. In Postman I send a POST request by specifying parameters and uploading a .csv file using form-data in the body. My request always succeeds. However, when I try to translate this into Robot Framework (using the Requests Library), I get a 400 Error.
I am posting my code below.
I have been trying to resolve this issue for a while now. Any help in the right direction would be much appreciated!
Create Session Alias http://{{HOST}}{{PORT}}
${data} Create Dictionary inputFileTypeId=1 dataType=csv
Set to Dictionary ${data}
${file_data} Get Binary File ${CURDIR}${/}File1.csv
${files} Create Dictionary file ${file_data}
Log ${files}
Log ${data}
${resp} RequestsLibrary.Post Request ALias /URI files=${files} data=${data}
Log ${resp}
Should Be Equal As Strings ${resp.status_code} 200
Create Session Alias http://{{HOST}}{{PORT}}
${data} Create Dictionary inputFileTypeId=1 dataType=csv
Set to Dictionary ${data}
${file_data} Get Binary File ${CURDIR}${/}File1.csv
${files} Create Dictionary File1.csv ${file_data}
Log ${files}
Log ${data}
${resp} RequestsLibrary.Post Request ALias /URI files=${files} data=${data}
Log ${resp}
Should Be Equal As Strings ${resp.status_code} 200
http://snomedct.t3as.org/ This is a web service that will analyse English clinical text, and report any concepts that can be detected.
For e.g.- I have headache. It will identify headache as a Symptom.
Now what I would like to do is send the sentence to the web service through R, and get the table back from the web page to R for further analysis purpose.
If we take their example curl command-line:
curl -s --request POST \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "The patient had a stroke." \
http://snomedct.t3as.org/snomed-coder-web/rest/v1.0/snomedctCodes
that can be translated to httr pretty easily.
The -s means "silent" (no progress meter or error messages) so we don't really have to translate that.
Any -H means to add a header to the request. This particular Content-Type header can be handled better with the encode parameter to httr::POST.
The --data-urlencode parameter says to URL encode that string and put it in the body of the request.
Finally, the URL is the resource to call.
library(httr)
result <- POST("http://snomedct.t3as.org/snomed-coder-web/rest/v1.0/snomedctCodes",
body="The patient had a stroke.",
encode="form")
Since you don't do this regularly, you can wrap the POST call with with_verbose() to see what's going on (look that up in the httr docs).
There are a ton of nuances that one should technically do after this (like check the HTTP status code with stop_for_status(), warn_for_status() or even just status_code(), but for simplicity let's assume the call works (this one is their example so it does work and returns a 200 HTTP status code which is A Good Thing).
By default, that web service is returning JSON, so we need to convert it to an R object. While httr does built-in parsing, I like to use the jsonlite package to process the result:
dat <- jsonlite::fromJSON(content(result, as="text"), flatten=TRUE)
The fromJSON function takes a few parameters that are intended to help shape JSON into a reasonable R data structure (many APIs return horrible JSON and/or XML). This API would fit into the "horrible" category. The data in dat is pretty gnarly and further decoding of it would be a separate SO question.
I configured a REST webservice (a Spring Boot webapplication) on WSO2 AM and used the default /* mapping for resources. My webservice takes an assignee (text) and file parameters.
When I perform the calls, I've noticed that request parameters are not forwarded (HTTP Headers are) to the backed services. For example:
curl -i -X POST -H "Content-Type: multipart/form-data" -H "X-PD20-BillingSubscriptionId: e87d4400-b05f-4f40-9c39-06ae4d28cf4d" -H "Authorization: Bearer rrxRV5F6jdkSBcEPXv7I1yFl2x8a" -F "documentFile=#src/test/resources/sample-files/test-fea-1firma.pdf" -F "assignee=bla.bla#gmail.com" http://api.linksmt.it:8280/fea/1.0.0/signRequest
As you can see, It's a form that posts 2 fields, one of them being a file and another a simple text field.
The call is succesfully forwarded to the backed service but without the actual fields values (the headers instead are correctly passed, though their keys are lower-cased, that is "X-PD20-BillingSubscriptionId" is passed as "x-pd20-billingsubscriptionid").
Any hint on why is this happening?
Thanks
Ok, the problem was the same as described in multipart form data file upload using WSO2 API manger ? and I had to uncomment the declarations for
within the $WSO2_AM/repository/conf/axis2/axis2.xml file (and restart the server).