how I can reuse the token from one collection to another in postman? So i can run in parallel multiple folders
I tried storing and reusing but haven't succeeded
pm.environment.set("token", responseBody.access_token);
Storing the token as global variable should do:
pm.globals.set("token", responseBody.access_token);
Postman has different variable scopes: Global, Collection, Environment, Data and Local:
Global variables enable you to access data between collections, requests, test scripts, and environments.
You can read more about it here: https://learning.postman.com/docs/sending-requests/variables/#variable-scopes
Related
I got a response from a get request as an object and added it to an environment variable. now I want to use it in another request params but I don't know how to do it.
You should use JSON stringfy in order to save in the environment. after that use the Pre-request Script in order to add query params and JSON parse to get data from the environment. follow these steps as a sample code.
1- pm.environment.set("key", JSON.stringfy(object))
2- go to Pre-request Script
3- var data = JSON.parse(pm.environment.get("key"))
4- pm.request.url.addQueryParams([`param=${data.child}`])
environment variables are just text, so you might need to strigify the json response object and parse it before executing the next request.
There are pre-requests tests that you could use to read and parse the environment variable.
https://learning.postman.com/docs/writing-scripts/pre-request-scripts/#pre-request-scripting-example
I have added a few tables on DynamoDB using the amplify add storage command.
But the table has a suffix that is the environment name (dev, prod, etc).
How can I access the environment name on my NextJS backend so I can suffix the DynamoDB table name on my code ?
Or there is another way to achieve what I want ?
Amplify automatically creates DynamoDB tables (and also AppSync queries, etc) to match your current Amplify environment. When you create a new environment (eg, 'dev'), the Amplify will automatically create duplicate 'prod' tables, that will perform the same as you 'dev' tables. I'm guessing in your case, you won't need to access environment variables.
If you are using AppSync/GraphQL to make calls, then you can use Amplify's built in dynamic env features here: https://docs.amplify.aws/cli-legacy/graphql-transformer/function/#usage
For example, you could set up a custom Lambda function to update your DynamoDB. You could then set up an AppSync call to that Lambda in your schema.graphql file.
There are some cases where you may need to access your environment variables. You can either set them up manually in .env.local, or possibly easier to run a query in your NextJS javascript to determine the current domain:
const origin =
typeof window !== "undefined" && window.location.origin
? window.location.origin
: "";
console.log(origin); // "https://dev.<>.amplifyapp.com"
An better solution would be to follow this Amplify documentation, except I've tried it and it doesn't work.
I get this in the left nav panel. I've explored each one and no sign of the described Environment Variables section:
It describes accessing/updating env vars here, but apparently you can only find/use this feature if you've connected your Amplify app to Github first. (It would have been nice if the docs had clarified this!)
I want to create postman scopes in local through pre-request. is it possible to create?
You can set Global Variables in Pre-request Script section.
If you want to store some value which can be used further. Then you can store that value in global variable and afterwards you can use it.
Ex.
pm.globals.set("Variable-Name","Variable-value");
Postman has been an amazing tool for me, but I have some questions about using variables. In my collection I have 4 tabs/requests.
The first is to get a token that is used in the other three (the token expires after 15 minutes so I have to rerun that request frequently and update the other 3). It needs to be passed in the headers of the other three requests. I'm familiar with the {{variable}} syntax, but I'm not sure how to dynamically set the variable after running the first request.
The second is similar, where I'd like to be able to set a string manually in some central location and use it in all of the requests. For instance, the URL is https://the.api.com/v1/{{someidvalue}}/abc so where can I change that in a single location manually to be reused across the collection?
Thank you!
To change the value based on server response you can use the test feature Postman test script
For exemple
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("Authorization","Bearer " + jsonData.result.accessToken);
The central location that you are looking for is the enviroment postman manage environments
I am using Google Speech API in my Django web-app. I have set up a service account for it and am able to make API calls locally. I have pointed the local GOOGLE_APPLICATION_CREDENTIALS environment variable to the service account's json file which contains all the credentials.
This is the snapshot of my Service Account's json file:
I have tried setting heroku's GOOGLE_APPLICATION_CREDENTIALS environment variable by running
$ heroku config:set GOOGLE_APPLICATION_CREDENTIALS="$(< myProjCreds.json)"
$ heroku config
GOOGLE_APPLICATION_CREDENTIALS: {
^^ It gets terminated at the first occurrence of " in the json file which is immediately after {
and
$ heroku config:set GOOGLE_APPLICATION_CREDENTIALS='$(< myProjCreds.json)'
$ heroku config
GOOGLE_APPLICATION_CREDENTIALS: $(< myProjCreds.json)
^^ The command gets saved into the environment variable
I tried setting heroku's GOOGLE_APPLICATION_CREDENTIALS env variable to the content of service account's json file but it didn't work (because apparently the this variable's value needs to be an absolute path to the json file) . I found a method which authorizes a developer account without loading json accout rather using GOOGLE_ACCOUNT_TYPE, GOOGLE_CLIENT_EMAIL and GOOGLE_PRIVATE_KEY. Here is the GitHub discussion page for it.
I want something similar (or something different) for my Django web-app and I want to avoid uploading the json file to my Django web-app's directory (if possible) for security reasons.
Depending on which library you are using for communicating with Speach API you may use several approaches:
You may serialize your JSON data using base64 or something similar and set resulting string as one environment variable. Than during you app boot you may decode this data and configure your client library appropriately.
You may set each pair from credentials file as separate env variables and use them accordingly. Maybe library that you're using support authentication using GOOGLE_ACCOUNT_TYPE, GOOGLE_CLIENT_EMAIL and GOOGLE_PRIVATE_KEY similar to the ruby client that you're linking to.
EDIT:
Assuming that you are using google official client library, you have several options for authenticating your requests, including that you are using (service account): https://googlecloudplatform.github.io/google-cloud-python/latest/core/auth.html You may save your credentials to the temp file and pass it's path to the Client object https://google-auth.readthedocs.io/en/latest/user-guide.html#service-account-private-key-files (but it seems to me that this is very hacky workaround). There is a couple of other auth options that you may use.
EDIT2:
I've found one more link with the more robust approach http://codrspace.com/gargath/using-google-auth-apis-on-heroku/. There is ruby code, but you may do something similar in Python for sure.
Let's say the filename is key.json
First, copy the content of the key.json file and add it to the environment variable, let's say KEY_DATA.
Solution 1:
If my command to start the server is node app.js, I'll do echo $KEY_DATA > key.json && node app.js
This will create a key.json file with the data from KEY_DATA and then start the server.
Solution 2:
Save the data from KEY_DATA env variable in the some variable and then parse it to JSON, so you have the object which you can pass for authentication purposes.
Example in Node.js:
const data = process.env.KEY_DATA;
const dataObj = JSON.parse(data);