REST API call works at Postman but not at Jenkins - api

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

Related

Same HTTPS request works in Postman but gives 400 Bad Request in JMeter

I think I tried all the possible combinations of headers and body for my POST request in JMeter but is giving me 400 Bad Request saying that the languagePairID parameter from the body is invalid even tho it is exactly same as in Postman.
My headers:
And the request:
Meanwhile in Postman in works perfectly fine:
I tried checking and unchecking the multipart/form-data and browser-compatible headers, but nothing seems to help. I read that using Wireshark might be useful in such cases but I think for this one is not possible as it is HTTPS. I will be very grateful for any advice.
Uncheck "Use mutipart/form-data"
Remove everything from the "Body Data" tab
Switch to "Parameters" tab and put your parameters there:
Going forward be informed that you can easily convert your Postman script into JMeter:
Start JMeter's HTTP(S) Test Script Recorder
Import JMeter's certificate to Postman
Configure Postman to use JMeter as the proxy
Run your request in Postman
JMeter will capture the request and generate relevant HTTP Request sampler and HTTP Header Manager
More information: How to Convert Your Postman API Tests to JMeter for Scaling

Response code:400 Response message:Bad Request Jmeter api testing with JIRA with POST method

When try to create issue in Jira using the JMeter API with POST method, it does not allow to create issue and it shows error below.
I uploaded my all configuration image.
Can anybody correct me?
Thanks in advance.
Error message:
2020-12-27 19:48:35,841 ERROR o.a.j.p.h.s.HTTPJavaImpl: readResponse: java.io.IOException: Server
returned HTTP response code: 400 for URL: https://learntestapi.atlassian.net/rest/api/2/issue
2020-12-27 19:48:35,841 ERROR o.a.j.p.h.s.HTTPJavaImpl: Cause: java.io.IOException: Server returned
HTTP response code: 400 for URL: https://learntestapi.atlassian.net/rest/api/2/issue
Screenshots (2 images attached)
I think you're using an incorrect URL, i.e. it has to be:
/rest/api/2/issue/createmeta/QA/issuetypes/{issueTypeId}
to identify the issueTypeId you need to first execute call to the following endpoint:
/rest/api/2/issue/createmeta/QA/issuetypes
then choose an appropriate issue type and substitute it in the first request.
More information: Jira REST API examples
Also make sure that your HTTP Header Manager is configured to send Content-Type header with the value of application/json

Unable to obtain LinkedIn Access Token using Authorization Code

I am unable to obtain a LinkedIn Access Token. My setup is as follows:
I have setup an app on LI with this redirect URL http://localhost:5000/home
I request authorization from LI and get a response with the 'code'.
In under 10 seconds, I copy the code query param out of the URL bar and paste it into Postman.
In Postman, I have a setup as follows:
POST /oauth/v2/accessToken HTTP/1.1
Host: www.linkedin.com
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&
client_id=<client id>&
client_secret=<client secret>&
redirect_uri=http%3A%2F%2Flocalhost%3A5000%2Fhome&
code=AQSbUzcWwSk_3sqQfusRZWEa4tZqU_x4fSQKub9c3eoeCzZwNO2ZH8uAzJc-T0T40WRv6qNxNpCDxckEjuXHqb56ZhKQqReB5mDjm1kZrCrLlBBYhzyymF5oRzwNgObylJukUVQ_0OiSuE0W0RQ
I have made multiple attempts but in response, I get the following error.
{"error":"invalid_request","error_description":"Unable to retrieve access token: appid/redirect uri/code verifier does not match authorization code. Or authorization code expired. Or external member binding exists"}
We have a LI login deployment that suddenly stopped working and started returning this error. On simplifying the use case, I find that Postman does the same.
What gives? What am I doing wrong? This used to work!

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.

PUT/POST request in SOAPUI giving 403 forbidden, while same request working fine in rest client Postman

There is no authentication on server side so authentication should not be issue.
URL format: PUT
https://localhost/api/v1/protections?integrationKey=111&userKey=1111&group=111&category=foo
Payload:
{"action":"BLOCK"}
This is working fine in Postman.
In SOAP UI , I am giving input as under:
EndPoint: https://localhost
Resource: /api/v1/protections
Parameters:?integrationKey=111&userKey=1111&group=111&category=foo
in Media type, I am selecting "application/json"
and entering {"action": "BLOCK"} but getting "Wed Jan 20 16:25:27 PST 2016:DEBUG:Receiving response: HTTP/1.1 403 Forbidden
"
Is there any suggestion to get the output in SOAP UI.
Depending on the server where the rest is exposed service generates an HTTP 403, you should verify that server is and thus find the fastest response.
Also try making a GET request from the browser to see if you can answer correctly because problem lock your machine to the server.
As is https, it may be that you lack some certificate set SOAPUI. possibly Postman you use already has configured. Try to check this setting.
In my case, I missed the Header "User-Agent" and "accept". I put in Soap UI and Works.
In Postman, this headers it put automatically.