from first request i get a list of url :
(30) ["https://pokeapi.co/api/v2/pokemon/1/", "https://pokeapi.co/api/v2/pokemon/2/", "https://pokeapi.co/api/v2/pokemon/3/", "https://pokeapi.co/api/v2/pokemon/4/", "https://pokeapi.co/api/v2/pokemon/5/", …]
i have to access to each url and find a value in the respone .
I saved the first response a var = url, the pre-requiste of the second request is : var url2 = pm.collectionVariables.get("url") , but, of course, it's using all urls..
can you help me?
Related
Scenario: Verify that Authentication is done or not
Given url '***********'
Given path 'authenticate'
And form field username = 'admin_cs'
And form field password = '********'
When method post
Then status 200
And header tokenn = response.token
* def accessToken = response.token
* print accessToken
Scenario: Verify Get all Clients
Given url '************'
Given path 'users/usersAssignable'
* header x-auth-token = accessToken
When method get
Then status 200
* def response = response
* print response
Please combine the two Scenario-s into one. Or move the first one here into the Background. Please read this very carefully: https://github.com/intuit/karate#script-structure
I'm trying to recreate a scenario with the postman and there is a _csrf value in the previous GET request response body to be passed with the next POST request.
I Can't find a way to extract the value from POSTMAN.
NOTE: What I want is something similar to Regular Expression Extractor in Jmeter.If you have any Idea about extracting a value form the response body and setting it to a variable. Please let me know.
Cheers,
Muditha
This might help you https://media.readthedocs.org/pdf/postman-quick-reference-guide/latest/postman-quick-reference-guide.pdf
They use Cheerio
2.2.5 How to parse a HTML response to extract a specific value?
Presumed you want to get the _csrf hidden field value for assertions or later use from the response below:
To parse and retrive the value, we will use the cherrio JavaScript library:
responseHTML = cheerio(pm.response.text());
console.log(responseHTML.find('[name="_csrf"]').val());
Cheerio is designed for non-browser use and implements a subset of the jQuery functionality. Read more about it at
https://github.com/cheeriojs/cheerio
responseHTML = cheerio(pm.response.text());
var po= responseHTML.find('[name="_csrf"]').val();
console.log(po);
pm.environment.set("token", po);
/* You need to set the environment in Postman and capture the CSRF token in variable "here po" using a get request. Next in post request the environment variable token can be used */
Just made this JS in post man to parse Without a REGEx. Hope it will help people in the futur
Text to parse : Json : Extract data-id :
{
"code": "OK",
"response": {
"append": {
"html": {
"< .folders": "<a class=\"folder\" href=\"/foobarfoo\" data-id=\"ToExtract\"><div><i class=\"far fa-fw fa-folder\"></i></div><div class=\"folder-name\">blabla</div><div><div class=\"badge\">0</div></div></a>"
}
}
}
}
console.log(responseBody.response);
var jsonData = JSON.parse(responseBody);
var iStart = responseBody.indexOf("response\":")+10;
var scenarioId = responseBody.substr(iStart,10);
var iEnd = scenarioId.indexOf("}");
var scenarioId = scenarioId.substr(0,iEnd);
console.log("scenarioId:" + scenarioId + "iStart: "+ iStart + " scenarioId : " + scenarioId);
pm.environment.set("scenario", scenarioId);
I'm trying to build a very simple app that will just output the raw JSON object from an api.
So I want a function that will take a url parameter and ideally return the JSON string.
I have the following code:
decode: String -> String
decode jsonString =
Decode.decodeString jsonString
apiResonse : String -> String
apiResonse url =
let
url = "https://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=cats"
request = Http.get Decode.decodeString url
in
Http.send NewRequest request
But I'm struggling to understand the decoder part of the function. If anyone could help me that would be great.
If you just want to get the HTTP response as a string value, use Http.getString. The example you posted using Http.get assumes the result is in JSON and forces you to decode it to an Elm value.
Here is a modified example of the random cat generator code which just displays a dump of the response JSON instead of a cat picture:
getRandomGif : String -> Cmd Msg
getRandomGif topic =
let
url =
"https://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=" ++ topic
in
Http.send NewGif (Http.getString url)
Here is a working example on ellie-app.com
I am new to elm,
I have a login api which returns a JWT token in its hedears
curl http://localhost:4000/api/login?email=bob#example&password=1234
response:
HTTP/1.1 200 OK
authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXyLp0aSI6ImefP2GOWEFYWM47ig2W6nrhw
x-expires: 1499255103
content-type: text/plain; charset=utf-8
success
now Im trying to write a function that will send request and return the token from the headers in elm
authUser =
Http.send "http://localhost:4000/api/login?email=bob#example&password=1234"
how do I do this in a simple way?
In order to extract a header from a response, you will have to use Http.request along with the expectStringResponse function, which includes the full response including headers.
The expectStringResponse function takes a Http.Response a value, so we can create a function that accepts a header name and a response, then returns Ok headerValue or Err msg depending on whether the header was found:
extractHeader : String -> Http.Response String -> Result String String
extractHeader name resp =
Dict.get name resp.headers
|> Result.fromMaybe ("header " ++ name ++ " not found")
This could be used by a request builder like so:
getHeader : String -> String -> Http.Request String
getHeader name url =
Http.request
{ method = "GET"
, headers = []
, url = url
, body = Http.emptyBody
, expect = Http.expectStringResponse (extractHeader name)
, timeout = Nothing
, withCredentials = False
}
Here is an example on ellie-app.com which returns the value of content-type as an example. You can substitute "authorization" for your purposes.
May I humbly suggest you look at my elm-jwt library, and the get function there?
Jwt.get token "/api/data" dataDecoder
|> Jwt.send DataResult
JWT tokens normally need to be sent as a Authorization header and this function helps you create a Request type that can be passed to Http.send or Jwt.send
I am making a request to http://translate.google.com/translate_tts?q=da%C3%B1o&tl=es-ES to get an audio recording. When I use System.Net.WebClient, System.Net.Http.HttpClient or WebRequest.Create, the request is sent as http://translate.google.com/translate_tts?q=daño&tl=es-ES instead. This second url works, but produces a incorrect result.
How can I send a request with %C3%B1 instead of ñ in the path?
Note that you cannot download these urls with a referral header (like, by clicking them) so if you click them they will fail and the result may be cached so that copy'n'pasting the url fails too. If you want to test the urls, copy them to the clipboard, then add to the q parameter to avoid cached results.
Adding repro where I tried using PUrify (same results as without):
var parameters = this.Bind<SpeechRequest>();
parameters.q = "daño";
parameters.tl = "es-MX";
var url = String.Format("http://translate.google.com/translate_tts?q={0}&tl={1}",
WebUtility.UrlEncode(parameters.q), WebUtility.UrlEncode(parameters.tl));
var uri = new Uri(url);
System.Console.WriteLine("Uri constructed from string: " + url);
System.Console.WriteLine("Before Purify: ");
ShowUriDetails(uri);
uri.Purify();
System.Console.WriteLine("After Purify:");
ShowUriDetails(uri);
var request = System.Net.WebRequest.Create(uri) as HttpWebRequest;
Output:
Uri constructed from string: http://translate.google.com/translate_tts?q=da%C3%B1o&tl=es-MX
Before Purify:
uri.ToString() - http://translate.google.com/translate_tts?q=daño&tl=es-MX
uri.AbsoluteUri - http://translate.google.com/translate_tts?q=da%C3%B1o&tl=es-MX
uri.Host - translate.google.com
uri.Query - ?q=da%C3%B1o&tl=es-MX
uri.PathAndQuery - /translate_tts?q=da%C3%B1o&tl=es-MX
uri.AbsolutePath - /translate_tts
uri.Fragment -
After Purify:
uri.ToString() - http://translate.google.com/translate_tts?q=daño&tl=es-MX
uri.AbsoluteUri - http://translate.google.com/translate_tts?q=da%C3%B1o&tl=es-MX
uri.Host - translate.google.com
uri.Query - ?q=da%C3%B1o&tl=es-MX
uri.PathAndQuery - /translate_tts?q=da%C3%B1o&tl=es-MX
uri.AbsolutePath - /translate_tts
uri.Fragment -