Post request with body and Image file in Robot framework - robotframework

I am trying to call a Post request which takes some key-values and files in body.But, Getting 400 bad request. Please let me know what am i missing here.
Post request with a Image File
${POST_HEADER}= Create Dictionary Authorization=Bearer ${token} Content-Type=applicaion/json
${org_post_body}= Create Dictionary title= Test Robot Post isPrivate=true
... description= Test Robot Post Description associationType=${assn_typ1}
... associationId=${org_id}
${img_file}= Get File For Streaming Upload ${CURDIR}\\pic1.jpg
${file}= Create dictionary files=${img_file}
${resp}= POST On Session host_server /api/post/ headers=${POST_HEADER} json=${org_post_body} files=${file}
Status Should Be 200 ${resp}
Without attaching imag file, API call is sucessful.Fails only when i try to attach image.
Attached the screenshot from postman where it iss uccesful with body as form-data. Trying to repeat same in robot framework.Postman success screesnhot

Pleae try puting your ${file} variable into dictionary org_post_body
So you gonna have something like this:
${org_post_body}= Create Dictionary title= Test Robot Post isPrivate=true
... description= Test Robot Post Description associationType=${assn_typ1}
... associationId=${org_id}
... files=${file}
And your request will looks like this:
${resp}= POST On Session host_server /api/post/ headers=${POST_HEADER} json=${org_post_body}

Related

RPTARQEMAIL : Run program with customed mail containing variables

I am using standard leave/attendance request process using PTARQ, and I've created a custom mail text to be sent through the program RPTARQEMAIL:
RPTARQEMAIL_customed_mails
In these email bodies, I have inserted &VARIABLES&, and I would like to run the program so that my &VARIABLES& are replaced by the real values of the leave/attendance request, but I can't find any parameters in the view for that. Is there another view of customizing I have to parameter? Do I have to overright a standard program or something?
Here is one of my mail templates :
Good morgning,
You have received a &LEAVE_OR_ATTENDANCE& request from &GENDER&
&EMPLOYEE_NAME& &EMPLOYEE_SURNAME&.
To validate or refuse the request, please clic on the link bellow :
&LINK_TO_CAINBOX&
Details of the request:
Type: &DESCRIPTION&
Begin: &BEGDA&
End: &ENDDA&
Best regards, HR Team

How to give empty value for argument in POST request for hyperledger composer rest server

I am trying to make a post request via R using the httr package to composer rest server. I have written a code and then created the composer rest server from it. These are my details
Request URL : http://localhost:3000/api/nl.amis.registry.fruits
Body: {
"$class": "nl.amis.registry.fruits",
"Id": "9",
"name": "orange",
"description": "string",
"count": ""
}
First, I have tried with the composer rest server. For my purpose, I needed the count to be blank and the value will be appended by another API call. I was able to make the transaction successfully with the count: "". This I was able to check in the test section of the composer playground. The remaining code works fine which appends the count variable later on.
Now I am writing an R code to make a similar transaction through POST request. Here I am facing an error that "count cannot be blank" and returns with error 422 Unprocessable entity. The content type I was used was application/json. While using the "count":{} , the post request process fine and i am getting "count":[object Object] in the response. But the later on code which does the appending will do something like count:"[object Object],1" wherein I am expecting "count":"1". Everything works fine while using the test in composer playground but while trying to access externally via rest API is creating the problem. Please help.
you can use an Optional keyword to declare a count in an asset of the model file. using Optional keyword you can post an empty value of count.
for example:
asset fruits identified by Id {
o String Id
o String name
o String description
o String count optional
}

Truncated data in the POST request erlang

I am trying to call an API from an ejabberd (17.04) module from erlang code by making a Post request. The API is called successfully, however, the data in the request body gets truncated.
Following is my erlang code to make the POST request.
Data = string:join(["to=", binary_to_list(To), "&from=", binary_to_list(From), "&body=", Body], ""),
Request = {binary_to_list(PostUrl), [{"Authorization", binary_to_list(Token)}], "application/x-www-form-urlencoded", Data},
httpc:request(post, Request,[],[]),
I pass the data with the application/x-www-form-urlencoded content type.
There is no error while compiling or running the code, however, if there are some special characters in the Body variable, then the data is not sent to the API.
For example, when the Body variable contains the following value:
{xmlel,<<\"encrypted\">>,\n [{<<\"xmlns\">>,<<\"eu.siacs.conversations.axolotl\">>}],\n [{xmlel,<<\"header\">>,\n [{<<\"sid\">>,<<\"344245169\">>}],\n [{xmlel,<<\"key\">>,\n [{<<\"rid\">>,<<\"684863397\">>}],\n [{xmlcdata,<<\"MwohBTL6tSWIPtugiO0qo0RNrWFC3ypIL5JpwMN1qF8jAoQ1EAAYASIwKnIw/zo43lF4At93Q7PMePlDVGF47Hf6xIvSjm+bpcESskndwFudirxigLSqc6J/P0IEL3sErsE=\">>}]},\n {xmlel,<<\"iv\">>,[],\n [{xmlcdata,<<\"JR7NorYN19NBDwyY3eqXcg==\">>}]}]},\n {xmlel,<<\"payload\">>,[],\n [{xmlcdata,<<\"Da1s4qj6MiPgE1CP9S1ou5Cod//QAfmguc5GUGEk7IfTUJ8VU9CvL6iOfI3qK6Rg7uVNWACTWKBqCWGQstBkEEkwLDZHzJBqoJ6CoE4vxyfEdowWLqt84fNhGcsgvVxqmEDIln0NA2gDRd/vhGi0yIh2JdMQ55+6Ten1+fVb+kwYlKxe94XyMV84Yiz+bfPkAach22oYCZyMx695JSBnaUb8MRLISlnkcpLv/UJtmEMlGER/t5Ac5BK00sbkbVo4zOMbfOgA++prt4mbpceTGyJpmkRa/75xoqDPbYxG3sYujq52RguW1YO649M=\">>}]}]}
The Data variable contains the following value:
"to=186&from=274&body={xmlel,<<\"encrypted\">>,\n [{<<\"xmlns\">>,<<\"eu.siacs.conversations.axolotl\">>}],\n [{xmlel,<<\"header\">>,\n [{<<\"sid\">>,<<\"344245169\">>}],\n [{xmlel,<<\"key\">>,\n [{<<\"rid\">>,<<\"684863397\">>}],\n [{xmlcdata,<<\"MwohBTL6tSWIPtugiO0qo0RNrWFC3ypIL5JpwMN1qF8jAoQ1EAAYASIwKnIw/zo43lF4At93Q7PMePlDVGF47Hf6xIvSjm+bpcESskndwFudirxigLSqc6J/P0IEL3sErsE=\">>}]},\n {xmlel,<<\"iv\">>,[],\n [{xmlcdata,<<\"JR7NorYN19NBDwyY3eqXcg==\">>}]}]},\n {xmlel,<<\"payload\">>,[],\n [{xmlcdata,<<\"Da1s4qj6MiPgE1CP9S1ou5Cod//QAfmguc5GUGEk7IfTUJ8VU9CvL6iOfI3qK6Rg7uVNWACTWKBqCWGQstBkEEkwLDZHzJBqoJ6CoE4vxyfEdowWLqt84fNhGcsgvVxqmEDIln0NA2gDRd/vhGi0yIh2JdMQ55+6Ten1+fVb+kwYlKxe94XyMV84Yiz+bfPkAach22oYCZyMx695JSBnaUb8MRLISlnkcpLv/UJtmEMlGER/t5Ac5BK00sbkbVo4zOMbfOgA++prt4mbpceTGyJpmkRa/75xoqDPbYxG3sYujq52RguW1YO649M=\">>}]}]}"
However, when I try to fetch this value in my API, only the following data is available:
{xmlel,<<\"encrypted\">>,\n [{<<\"xmlns\">>,<<\"eu.siacs.conversations.axolotl\">>}],\n [{xmlel,<<\"header\">>,\n [{<<\"sid\">>,<<\"344245169\">>}],\n [{xmlel,<<\"key\">>,\n [{<<\"rid\">>,<<\"684863397\">>}],\n [{xmlcdata,<<\"MwohBTL6tSWIPtugiO0qo0RNrWFC3ypIL5JpwMN1qF8jAoQ1EAAYASIwKnIw/zo43lF4At93Q7PMePlDVGF47Hf6xIvSjm+bpcESskndwFudirxigLSqc6J/P0IEL3sErsE
I am new to erlang and not sure of what seems to be the problem. Any help is appreciated.

AWS API/Lambda POST capabilities

I am trying to create a API/Lambda process which takes a comment and posts in into my RDS Aurora database.
The comment field in the database is set as TEXT type
The lambda function posts the comment to the database
The API method is POST
A mapping template has been set u to map the request body into the lambda function
All work perfectly until I start to try and post large comments. (A large paragraph, maybe 500 characters)
The body looks as follows:
{
"comment":"long comment"
}
When I run it in Lambda, I can post massive comments, however when I try and do it through the API Gateway I get an error
Endpoint response body before transformations: {"stackTrace": [["/var/task/app.py", 38, "handler", "raise Exception('Internal Error: Unable to post the comment.')"]], "errorType": "Exception", "errorMessage": "Internal Error: Unable to post the comment."}
I would suggest to use the test invoke feature on API Gateway console. From there, you can see the payload before transformed and after transformed. That might be a bit on debugging.

Benchmarking Solr indexing with Jmeter

I want to use Jmeter to update a document on solr using http post.
I want it to take a different file to update in every iteration, create a proper http post request and monitor the responses from the server.
Can someone guide me of how this can be done:
Taking a different file every time.
Creating a http post from it.
Your use case can be split into 2 parts:
Get list of files to send
Send them to server
In regards to point 1, I would suggest to obtain file list via scripting.
Assuming following Test Plan Structure:
Add a Thread Group (all defaults)
Add a JSR223 Sampler as a child of Thread Group
Select "beanshell" as language
In "Script" area add following code:
File folder = new File("PATH TO FOLDER WITH YOUR FILES");
File [] files2send = folder.listFiles();
int counter = 1;
for (File file : files2send)
{
vars.put("FILE_" + counter, file.getPath());
counter++;
}
This will save files, you will be sending as JMeter Variables like:
FILE_1=d:\2solr\sometxtfile.txt
FILE_2=d:\2solr\somewordfile.docx
FILE_3=d:\2solr\someexcelfile.xlsx
After that you can use For Each Controller to iterate through files and add them to your request
Add For Each Controller as a child of Thread Group (same level as JSR223 Sampler)
Make sure that For Each Controller has following configuration:
Input variable prefix: FILE
Output variable name: CURRENTFILE
Add _ before number is checked
Add HTTP Request as a child of For Each Controller
Access file you want to send as ${CURRENTFILE} in "Send Files With The Request" stanza of the HTTP Request
It's just one of the approaches, if you are not very comfortable with JSR233 or Beanshell you may wish to use CSV Data Set Config instead.

Resources