Exporting AUth2.0 bearer token with postman collection file does NOT work when executed using newman on cmd - api

Below are the steps
Add bearer token env variable, as shown below
Add bearer token to the header on Main collection tab, and the request
as shown below
And now manually check what happens when we run - Get comments request, use the 'inherit auth from parent' option - it shows 200 OK, and returns the comments as shown below
Now export both env variables & collection file as shown below
Run the files on cmd with newman as shown below
Check the result of the 'Get Comments' request
Expected: 200 OK status
Actual : 401 Unauthorized stauts
Any help will be really appreciated, thanks

Every Sub folder should refer to the 'inherit from parent ' in the auth method . In this case, make sure the sub folder ACCOUNT has the auth method set to 'inherit from parent'. And make sure to click the save button before exporting the collection file.

Related

How to save JSON Input body parameter to global variable in POSTMAN (Check image)

How to save JSON Input body parameter to a global variable in POSTMAN (Check image)
Click the Environment quick look (eye button) in the top right of Postman and click Edit next to Globals.
Add a variable named timestamp and give it an initial value, Save and close the environment modal.
Open a new request tab and enter https://postman-echo.com/get?var={{timestamp}} as the URL. Hover over the variable name and you'll see the value.
Send the request. In the response, you'll see that Postman sent the variable value to the API.
Note :No need for "$"
In order to get that value from the Request Body, you can add a simple script like this to the Tests tab:
let depositRef = JSON.parse(pm.request.body.raw).api_data.deposit_reference
pm.globals.set('depositRef', depositRef)
This is using pm.request.body.raw from the pm.* API to grab the value from the Request Body.
You need to add this to the Tests rather than the Pre-request Script, as that would set the Global variable but it wouldn't resolve the dynamic variable at that point and it would just store TX1{{$timestamp}}.

Github Enterprise Raw URL Gist Unable to Download

I'm able to get a list of gists and their files https://api.git.mygithub.net/users/myuser/gists?per_page=100&page=1 which I found using the docs here: https://docs.github.com/en/free-pro-team#latest/rest/reference/gists#get-a-gist
The files on the gist object have a raw_url. If I fetch the raw_url with the same token, it fails wanting me to authenticate. If I add the header: Accept: application/vnd.github.v3.raw it returns a 406 Not Acceptable. I've references to that header around.
I'm not sure what the scope should be on the token. It seems like it would be the same one I accessed the API. In the UI if you click the raw file it gets a token appended to the url. That token doesn't look like one of the Private tokens mentioned here: https://docs.github.com/en/free-pro-team#latest/github/authenticating-to-github/creating-a-personal-access-token
So what is the format of the HTTP request to download the raw gist?
The raw url needs to have the hostname of gist. changed to raw. and the url path needs to start with /gist/.
Example code in Go fixing it:
url := gistFile.RawUrl
url = strings.Replace(url, "gist.", "raw.", 1)
url = strings.Replace(url, ".net/", ".net/gist/", 1)

Include request parameters in URL when using Postman

I need to fire some requests using Postman but I need to include the parameter in the URL.
What I need:
https://serveraddress/v1/busride/user/favorites/route/RanDOMid
What I currently can configure in Postman:
https://serveraddress/v1/busride/user/favorites/route/?id=RanDOMid
I do not control the server, so I need to work it out how to craft the request in Postman to accept the input data as part of the URL, not as parameter. How can I specify input data in Postman to get it included in URL?
Click on Manage Environment
Add variable as path with Initial and current value as RanDOMid
Add path to URL:
https://serveraddress/v1/busride/user/favorites/route/{{path}}
#User7294900's answer should do for you in case all you want to do is include a variable in your request URL.
However, if you want to actually generate a random ID for every request, you may use {{$guid}} or {{$randomInt}} directly in you URL as follows:
https://serveraddress/v1/busride/user/favorites/route/{{$guid}}
This will generate a random GUID every time your request is fired and the generated GUID will replace {{$guid}} in your URL.
or
https://serveraddress/v1/busride/user/favorites/route/{{$randomInt}}
This will generate a random integer between 0 and 1000 every time your request is fired and the generated integer will replace {{$randomInt}} in your URL.
Refer postman documentation for more details - https://www.getpostman.com/docs/v6/postman/environments_and_globals/variables
Hope this helps!

Authorization type Bearer Token on Postman

I'm trying test a few endpoints using Postman.
All endpoint, require a token which can be obtain by log-in.
So I did this :
Request #1
After login success, I have access to the token from the response, then I store that token in my global variable.
let token = pm.response.json().location
console.log('Token : ', token.split("?token=")[1]);
pm.globals.set("token", token)
I need to use that token as Authorization type Bearer Token for my request #2.
I can copy & paste that in the token box, but I tried to avoid doing that manually, is there a way to do it automatically so I can run these 2 requests in sequence?
At first, create an environment ( top right corner of postman - image below ) This
is not a mandatory step by I suggest you to do for better handling of variables
I have modified the script to suit your need
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("ID", jsonData.Location.split("?token=")[1]);
Now this will export the value of the token ( screenshot below )
All you have to do next is to call the variable in request #2
By this you don't have to manually copy, paste into request #2 every single time
NO there isn't any till now. It has to be done manually if you want to have complete value or else you can store it in a variable and use that variable directly for the token.

Pipeline input step field "inputId" in Jenkins - API

Screenshot of pipeline-input-step (Proceed or Abort)
I could not figure out how is generated pipeline-input-step url parameter inputId which contains string similar to CRUMB (CSRF protection) or API TOKEN - it is not any of these. However main purpose of it is to use it in GUI, I would like to know how to initiate it through terminal as well.
Example of url (in POST method):
http://my-jenkins-url.com/job/NAME_OF_THE_JENKINS_JOB/6/wfapi/inputSubmit?inputId=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx