How to pull the token from Get request's response and input the same to Post request in JMeter for Rest API? - api

I am a beginner in JMeter, trying to perform load test to my Rest API. First, the Get request gets the access_token as below:
Then the following Post request runs with that authorization token to produce the Json, but I am missing something so the Post Request is failing as Authentication denied as below,
Added the Regular expression extractor to extract the token from the Get request's response as below:
Then storing it in the HTTP Header Manager in a variable as below
I am missing to link the value to the Post request, I dont know how to do it, please help.

In header manager, instead of access_token, the header name should be Authorization. Please reconfirm this with developer team / retry this same request in postman
The regex expression used should look something like this
"access_token":"(.*?)"
Also, another pro tip: because the response to getToken api call is JSON, you can use JSON Post Processor to extract the access_token by saying something like $.access_token. It is much clean way to process JSON object.

Related

Postman request - how to get data from endpoint based on API documentation

I want to retrieve data from a data warehouse that has a web-based API, I need to use an API key for authentication and use the GET / Customers command to retrieve the list of customers data, but when I am using that same thing in postman, it's returning the same documentation page of the data warehouse?
I am new to this any help will be really appreciated.
The URL doesn't look valid:
You need a base URL, endpoint, http method, authentication scheme, and credential or a token etc.
I don't know details about your system and API, so let's see an example:
base url is https://stackoverflow.com; your current base url is localhost:4444, is your server running on your machine? If so, it might be correct, but I assumer you're talking about a server running somewhere else, not on your computer
endpoint (path parameter) is /questions/69883697, in your case /customers
http method is GET and you find it here in Postman; it also means it will not go into query parameters where you put it:
authentication scheme - your docs mentions an api key that goes into a header called Authorization, so you have to set it in Headers, not as a query parameter:
Read carefully what's on your screen, Postman uses the same language as your API documentation, so if your doc speaks about headers, you need to go into Headers tab in Postman.

Getting "Enter a valid json" when entering Headers for HTTP with Azure AD in Microsoft Flow/Power Automate

I'm working on setting up a flow that will make an API request against a protected API. Since it requires authentication, I'm using HTTP with Azure AD. I'm able to sign in correctly, and I appear to be getting an authorization code:
I'd like to exchange this code for an access token so I am invoking this HTTP request:
It's complaining about the Headers not being a valid json. I'm also not sure what to include in the Body to exchange the authorization code for an access token.
Since I don't know much about this connector, so I'm sorry that I can't explain to you why your API calls still require logging in(which you asked in previous post). But if just for the questions and screenshot you provided above, I can provide some suggestions for your reference.
In you power-automate, you can add a "Initialize variable" action to initialize a variable named "header" and set the value shown as below screenshot:
Then you can use "Parse JSON" action to parse this variable(convert it to json format)
Now you can use the "Body" from the "Parse JSON" as the value of the "Headers" box in your "Invoke an HTTP request". It will solve the issue of headers not being a valid json.
For the value of "Body of the request", you can put the value as I provided in the previous post:
grant_type=password&client_id=xxxxx&scope=xxxxx&username=xxxxx&password=xxxxxclient_secret=xxxxx
Hope it would be helpful to your problem~

How do i get the csrf token from scenario 1 response using Karate framework?

I have application api url which has passed as Background with Basicauth. Using that i need to get an csrf token. I tried with responsecookies. Nothing is coming up.
Can you please let me know how to get the csrf token from that specific api. I am getting actual application response but not the cookies.
Please read the documentation and go through the demo examples. It depends on the response. There are 2 possibilities, cookie (or header) OR the response body itself (plain text or JSON / XML).
So it is up to you to extract it and then store it as a variable, and use it to build headers for all future responses.
Please refer to the demo example:
Given path 'signin', 'token'
When method get
Then status 200
And header X-CSRF-TOKEN = response
In this case, the token happened to be the entire response string.

How do I create a mock server backend API with Postman?

I'm not understanding this tutorial.
I have a collection set up in Postman, I created a GET request in the collection and an example.
I'm not sure what to put in the request URL for the mock API example and what values to put in key/value in the request call.
Following the examples from the Postman documentation you mentioned - At Step 5 you should have a mock for the collection:
I've saved a simple GET request http://jsonplaceholder.typicode.com/users to the collection using the free jsonplaceholder API which will return details about users.
Once you have that response, hit the "Save Response" button and this will save that response as an example that can use with the mock server.
You can make requests against the mock server URL and add your route to the end of this in the Request Field. For me, it would look something like https://914aae16-28d5-47f1-8954-8a4d7b5e1daf.mock.pstmn.io/users

Survey Monkey API- Getting Long Lived Access Token

I am currently unable to figure out how to obtain my long-lived access token so I can create an API data feed from Survey Monkey to Alteryx.
Thus far I have been able to:
1) Go to the OAUTH page
https ://api.surveymonkey.net/oauth/authorize?redirect_uri=https:// www.surveymonkey.com&client_id=[MY-CLIENT-ID]&response_type=code
2) Authenticate access (I am not a robot: reCAPTCHA)
3) Get the Authentication Response with the short-lived code
https: //www. surveymonkey.com/home/?code=[CODE-FROM-RESPONSE]
4) Got stuck
From: https://developer.surveymonkey.com/docs/guides/oauth-guide/
To make the exchange, simply create a form-encoded ( Content-Type: application/x-www-form-urlencoded) HTTP POST request to https://api.surveymonkey.net/oauth/token?api_key=YOUR_API_KEY with the following encoded form fields: client_secret, code, redirect_uri and grant_type. The grant type must be set to "authorization_code".
This is not a "simply" for me, and would really appreciate the expression so I can enter that into my browser so I can retrieve my long-lived access token.
End goal is that I am using Alteryx to pull in the Survey Monkey data via API and creating a blended data set with additional system data. The combined data set will then feed a Tableau Dashboard. I'm sure it is a long-shot, but if anyone has an Alteryx workflow for Survey Monkey API that would solve all of my issues at once.
Thank you in advance for your insights/ guidance.
With gratitude,
Drew
(Note- I added spaces to a few of the links, as I do not have 10 reputation points; yet).
There is an example cURL request at the side of the docs here. You need to make a POST request to /oauth/token. It'll look something like this:
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d 'code=<code>&client_id=<client_id>&client_secret=<client_secret>&redirect_uri=<redirect_uri>&grant_type=authorization_code' "https://api.surveymonkey.net/oauth/token"
Filling in the values in <>. Or in Python, something like this should work:
import requests
url = "https://api.surveymonkey.net/oauth/token"
payload = {
"code": "<code>",
"client_id": "<client_id>",
"client_secret": "<client_secret>",
"redirect_uri": "<redirect_uri>",
"grant_type": "authorization_code"
}
headers = {
'content-type': "application/x-www-form-urlencoded"
}
response = requests.request("POST", url, data=payload, headers=headers)
I'm pretty sure the requests library will automatically convert the body to the right type, but if not payload just looks like URL params:
payload = "code=<code>&client_id=<client_id>&client_secret=<client_secret>&redirect_uri=<redirect_uri>&grant_type=authorization_code"
Essentially though, you just need to make a POST request to /oauth/token with the payload provided above (code, client_id, client_secret, redirect_uri, and grant_type). The main confusing part is you can't send in a JSON body, it has to be a form body that looks like my example above.
Hope that helps.
You should be able to take the response that General Kandalaft has provided and enter each of those into the Download Tool in Alteryx. Create a field for each of client id, client secret, code, redirect_uri & grant_type and then tick those fields on the Payload Tab.
Set the HTTP Action to POST on the same tab.
There are also some examples of Oauth processes on the Alteryx Community and Gallery.
In general, when converting cURL requests to the Download Tool, -d/-F will be payload tab and -H of course will be Headers tab. form encoded etc is normally correct already and only needs to be added/changed very occasionally.
As another note, if you can't figure out the conversion of a cURL request or it's more complicated (i.e. attaching a PEM file to the call), you will find a copy of cURL in your Alteryx install directory and you can use the Run Command Tool to run that.
Kane