Unable to test an API in JMeter where I need to upload a file - api

can someone please help me with uploading a file on JMeter I feel its very tricky thing...
let me share the screen shot of what I've done
enter image description here
Its failing with below error:
Thread Name:jp#gc - Ultimate Thread Group 2-4
Sample Start:2021-02-04 17:28:44 IST
Load time:562
Connect Time:0
Latency:562
Size in bytes:595
Sent bytes:84568
Headers size in bytes:446
Body size in bytes:149
Sample Count:1
Error Count:1
Data type ("text"|"bin"|""):text
Response code:500
Response message:
HTTPSampleResult fields:
ContentType: application/json
DataEncoding: null
Response Body:
{"timestamp":"2021-02-04T11:58:45.482+00:00","status":500,"error":"Internal Server Error","message":"","path":"/pps/storage/upload-image"}
Request Body:
POST https://pixelperfectdevexternal.useready.com/pps/storage/upload-image
POST data:
--axOhwnTOrVj2VWGGuxcaqfjgHwGQKsTFl
Content-Disposition: form-data; name="filename"
Content-Type: image/jpeg; charset=US-ASCII
Content-Transfer-Encoding: 8bit
${filename}
--axOhwnTOrVj2VWGGuxcaqfjgHwGQKsTFl
Content-Disposition: form-data; name="filename"; filename="Passport size photo.jpeg"
Content-Type: image/jpeg
Content-Transfer-Encoding: binary
<actual file content, not shown here>
--axOhwnTOrVj2VWGGuxcaqfjgHwGQKsTFl--
I'm totally stuck on this from last 3 weeks, I did what was told in tutorials and still its not working, someone please help me out.

We don't know how to fix the issue because we don't know how the request should look like, moreover you don't show us "Parameters" tab of the HTTP Request sampler and HTTP Header Manager configuration.
So if you have another way of successfully calling this API like curl or Postman or other tool - you should be able to record the request using JMeter's HTTP(S) Test Script Recorder, see How to Convert Your Postman API Tests to JMeter for Scaling article for example setup.
If not, you need to check your API endpoint documentation, application logs or ask around for the proper request format, once you know it you should be able to amend the request yourself or provide us more details so we could assist.

Related

How to upload a pdf file in JMeter along with Json body through API as a request without converting the pdf file into bytecode

can someone please help me to upload a pdf file along with JSON body as a request through API using JMeter?
JSON Body:- {
"name" :"xyz",
"token" : "123OuvP4"
}
Pdf file name - PT_001.pdf
API URL - apiq-bbmma-stq.azure-api.net/DocMqmt/UploadDocument
Header Manager : - Content-Type:- multipart/related; Boundary:-"Aa0b12x"
please guide me on how to do that without converting the pdf file into bytecode
I'm not getting your requirement. You should be sending the PDF file "as it is" in a separate "part" of the multipart request.
In case of Multipart Content-Type you need to send the message like:
--Aa0b12x
Content-Type: application/json; charset=UTF-8
{
"name": "xyz",
"token": "123OuvP4"
}
--Aa0b12x
Content-Type: application/pdf
your-pdf-file-content-here, it may be either "raw" or i.e. Base64-encoded
--Aa0b12x--
If you cannot build the request manually try just recording it using HTTP(S) Test Script Recorder, just make sure to copy the PDF file to JMeter's "bin" folder before uploading, this way JMeter will capture the request and generate proper HTTP Request sampler and HTTP Header Manager. More information: Recording File Uploads with JMeter

REST API call works at Postman but not at Jenkins

I'm facing a problem that seems to be simple. I'm trying to call a REST API from Jenkins build step and it's not working.
I make this call from postman and it works just fine, but from Jenkins, it doesn't. Bellow are some pictures of my configurations.
Postman Settings
As you can see on this image, at postman my request works perfectly.
Jenkins Settings
At this image you can see that I'm using the same settings at Jenkins, although it doesn't work.
Finally, the error message that is presented when I try to run the Jenkins.
Started by user Hugo da Silva da Silva
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/Power BI - Atualizador mensal
HttpMethod: POST
URL: https://login.windows.net/7348b8c4-3705-4965-b18a-c02e2d5a28eb/oauth2/token
Content-Type: application/x-www-form-urlencoded; charset=ISO-8859-1
Accept: application/json
Sending request to url: https://login.windows.net/7348b8c4-3705-4965-b18a-c02e2d5a28eb/oauth2/token
Response Code: HTTP/1.1 400 Bad Request
ERROR: Build step failed with exception
hudson.AbortException: Fail: the returned code 400 is not in the accepted range: [[100‥399]]
at jenkins.plugins.http_request.HttpRequestExecution.responseCodeIsValid(HttpRequestExecution.java:369)
at jenkins.plugins.http_request.HttpRequestExecution.processResponse(HttpRequestExecution.java:379)
at jenkins.plugins.http_request.HttpRequestExecution.authAndRequest(HttpRequestExecution.java:295)
at jenkins.plugins.http_request.HttpRequestExecution.call(HttpRequestExecution.java:226)
Caused: java.lang.IllegalStateException
at jenkins.plugins.http_request.HttpRequestExecution.call(HttpRequestExecution.java:229)
at jenkins.plugins.http_request.HttpRequestExecution.call(HttpRequestExecution.java:79)
at hudson.remoting.LocalChannel.call(LocalChannel.java:45)
at jenkins.plugins.http_request.HttpRequest.perform(HttpRequest.java:398)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
at hudson.model.Build$BuildExecution.build(Build.java:206)
at hudson.model.Build$BuildExecution.doRun(Build.java:163)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
at hudson.model.Run.execute(Run.java:1856)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:428)
Build step 'HTTP Request' marked build as failure
Finished: FAILURE
Anybody has ever faced a similar situation? Any tip?
Best Regards
Posting here the solution given by my friend #brunolmfg.
The problem was the body content format. I was posting it using json format, whereas I shoud post it as url encoded. Here is the body content that worked:
grant_type=client_credentials&resouce=XXX&client_id=YYY&client_secret=ZZZZ

Content-Encoding response header not returned in karate GET call

Actually I was trying to migrate my old test suite to Karate framework.
And I have to validate response headers, In that "Content-Encoding" header is not returned in Karate GET call - I checked it in results I could see all other response headers but not "Content-Encoding" and returns null for assertion.
The same GET call I checked it in chrome browser - developer console and POSTMAN in both the tools I could get "Content-Encoding" but not in Karate.
Please help me in this.
If the server returns Content-Encoding you will see it else you will not.
To validate that a header does NOT exist, it is simple:
And match responseHeaders contains { 'Content-Encoding': '#notpresent' }
Refer responseHeaders: https://github.com/intuit/karate#responseheaders
Unfortunately it does not provide all response headers, because some, like "Content-Encoding: gzip" are stripped away by underlying Apache http libraries after decompressing the content it seems.
See:
Having trouble getting content-encoding to show up in response header for get request

Jmeter - POST API not working

I am new to Jmeter and have been struggling to get it working to test my POST API. It works fine for a GET API call where I pass the parameters through the Parameters tab.
Details here:
server name: localhost
port: 8080
path /registerMobileUsingCode
In the request body, I am sending the following:
{
"clientName": "DemoOrg",
"code": "9880007615",
"languageId": "1"
}
My Jmeter setup looks like this:
And my HTTP Request Header looks like this:
The API is in production and works fine with postman.
I am just unable to get it working through JMeter. It is obvious that I am doing something wrong but can't figure out what despite having spent a considerable amount of time Googling for solutions.
Any help would be much appreciated.
UPDATE - 1 - Updated with jmeter log as suggested
Thread Name: Thread Group 1-1 Sample Start: 2017-08-09 17:03:41 IST Load time: 1604 Connect Time: 1525 Latency: 1604 Size in bytes: 399
Sent bytes:251 Headers size in bytes: 213 Body size in bytes: 186
Sample Count: 1 Error Count: 1 Data type ("text"|"bin"|""): text
Response code: 500 Response message: Server Level Exception
encountered
Response headers: HTTP/1.1 500 Server Level Exception encountered
Date: Wed, 09 Aug 2017 11:33:43 GMT Access-Control-Allow-Origin: *
Content-Type: application/json Transfer-Encoding: chunked Server:
Jetty(9.2.16.v20160414)
HTTPSampleResult fields: ContentType: application/json DataEncoding:
null
UPDATE-2 - Using Postman and JMeter Recorder
As suggested by #Dimitri T, I downloaded the Linux version of Postman and started it with --proxy-server=localhost:8888.
I was now able to make a Postman request and capture the request in JMeter. Here is what the request looked like:
Jmeter capture of a Postman Request
As you can see, nothing radically different from what I did. However, this DOES work! So hurray!
If your application works fine with Postman the fastest and the easiest way of building JMeter test plan will be just recording it using JMeter's HTTP(S) Test Script Recorder.
Prepare JMeter for recording (you can do it in a few clicks via JMeter Templates Feature)
from JMeter's main menu choose File -> Templates -> Recording and click "Create"
Expand Workbench - HTTP(S) Test Script Recorder and click "Start"
Prepare Postman for recording
In order to "tell" Postman to use JMeter as a proxy you need to provide --proxy-server parameter to it like:
C:\Users\YOUR_USER_NAME\AppData\Local\Postman\app-x.x.x\Postman.exe --proxy-server=localhost:8888
Execute your requests in Postman
JMeter will capture requests, convert them into HTTP Request samplers and store them under Test Plan -> Thread Group -> Recording Controller
References:
JMeter Proxy Step by Step
How to configure Postman Native Client App to use an external proxy
By seeing the image you have attached you are missing / in the path.
the path should be /registerMobileUsingCode
if it is working fine from POSTMAN, then your port 8080 is fine.
Can you please confirm what is the data type of your request? looks like languageId is integer so you should be using languageId: 1, instead of languageId: "1". The integer should not be double quotes.

Add file programmatically to IBM Connections Community

I am trying to upload files programmatically to an IBM Connections Community File library.
I am able to upload to files and then share with the community, but unfortunately is not the desired behavior.
I followed the API documentation (http://www-10.lotus.com/ldd/lcwiki.nsf/xpAPIViewer.xsp?lookupName=IBM+Connections+5.0+API+Documentation#action=openDocument&res_title=Creating_community_files_ic50&content=apicontent)
I am sending a POST to this URL: /files/basic/api/community/{community_uuid}/introspection
I tried using a file Atom Entry document, and Content-Type:application/atom+xml
But it's not working and giving me a 405 with following error:
UnsupportedOperation
-> Request sent
POST /files/basic/api/community/00f04081-f000-4752-bd88-8b73d281fb19/introspection
Content-Type: application/atom+xml
<?xml version='1.0' encoding='UTF-8'?>
<entry
xmlns:thr='http://purl.org/syndication/thread/1.0'
xmlns:opensearch='http://a9.com/-/spec/opensearch/1.1/'
xmlns:snx='http://www.ibm.com/xmlns/prod/sn'
xmlns:td='urn:ibm.com/td'
xmlns='http://www.w3.org/2005/Atom'>
<td:label>test-restore20</td:label>
<title type="text">test-restore2</title></entry>
I tried using the same method than for stand alone file, with a basic header but still giving me a 405 with following error:
UnsupportedOperation
-> Request sent:
POST /files/basic/api/community/00f04081-f000-4752-bd88-8b73d281fb19/introspection
Content-Type: binary/octet-stream
X-Update-Nonce:<Nonce>
Slug:TMap_Next_Book.pdf
Filename: /Users/Downloads/TMap_Next_Book.pdf
When I upload to myfile, works fine
-> request sent:
POST https://greenhouse.lotus.com/files/basic/api/myuserlibrary/feed
X-Update-Nonce: <Nonce>
Slug: test-restore2
Content-Type: application/binary
Filename: /Users/Downloads/client-error-log.zip
I tried the Playground, but not well documented for that part, so so far no success.
Any of you were able to do that, and would be able to share the solution?
Thanks.
Rightfully this document should be called working with IBM Connections Community Files
http://www-10.lotus.com/ldd/lcwiki.nsf/xpAPIViewer.xsp?lookupName=IBM+Connections+5.0+API+Documentation#action=openDocument&res_title=Creating_community_files_ic50&content=apicontent
The introspection endpoint should be called to get the "community collection document feed"
it doesn't look like you have the URL parameter which is required. You should use the URL with a GET /files/basic/api/community/3a246a15-b4d6-44e1-a01d-1c3d89f1f9a4/introspection?communityUuid=3a246a15-b4d6-44e1-a01d-1c3d89f1f9a4
Then you'll look for
Community Collection
Documents Feed
/
You'll then POST your file to the href --- https://greenhouse.lotus.com/files/basic/api/collection/e78ba00e-cee6-460f-a9ee-0350bf344e0b/feed
I've asked the team to change the title of the page.