How to map/manipulate data in Postman Flows - postman

I've tried to transform data from API response in Postman Flows evaluate block using Postman FQL but unable to make it work. Here my script written in API tests
places.map(place => {
return {
id: place['id'],
dt: Object.assign({a: 1}, place['data'])
}
})
The code is straight forward, if the place data is null or missing a, append that field to the dt.
I am able to get the desired field in Postman evaluate but don't know how to append a to the dt
body.{
'id':id,
'dt': data
}
How can I do it in Postman Flows' evaluate?

I was hoping to have access to similar object manipulation methods in FQL as we have in JavaScript, such as merging objects and adding properties. Instead, I have to manually combine objects, which can be challenging as I need to be aware of the number of properties an object has and ensure that properties with null values do not cause any issues.

Related

How do I send a request multiple times while only changing the parameters in POSTMAN?

I'm very new to postman so please bear with me. Basically, I am trying to get data from the clinicaltrials.gov API, which can only give me 1000 studies at a time. Since the data I need is about 25000 studies, I'm querying it based on dates. So, is there any way in Postman that I can GET multiple requests at one time wherein I am only changing one parameter?
Here is my URL: ClinicalTrials.gov/api/query/study_fields??expr=AREA[LocationCountry]United States AND AREA[StudyFirstPostDate]RANGE[MIN,01/01/2017] AND AREA[OverallStatus]Recruiting
I will only be changing the RANGE field in each request but I do not want to manually change it every time. So, is there any other way in which I can maybe at a list of dates and have Postman go through them all?
There's several ways to do this.
So, is there any way in Postman that I can GET multiple requests at one time wherein I am only changing one parameter?
I'm going to assume you don't mind if the requests are sequenced or parallel, the latter is less trivial and doesn't seem to add more value to you. So I'll focus on the following problem statement.
We want to retrieve multiple pages of a resource, where the cursor is StudyFirstPostDate. On each page retrieved the cursor should increment to the latest date from the previous poge. The following is just one way to code this, but the building blocks are:
You have a collection with a single request, the GET described above
We will have a pre-request script that will read a collection variable with the next StudyFirstPostDate
We will have a test script (post-request) that will re-set the StudyFirstPostDate to the next value of the pagination.
On the test script you should save the data the same way you're doing now.
You set the next request (postman.setNextRequest("NAMEOFREQUEST")) to the same GET request we're dealing with, to effectively create a loop. When you've retrieved all pages you kill the looip with postman.setNextRequest(null) - although not calling any function should also stop it. This then goes to step (2) and loop.
This flow will only work on a collection run. Even if you code all of this, just triggering the request by itself will not initiate a loop. setNextRequest only works within a collection run.
Setting a initial value to the variable on the pre-request script
// Set the initial value on the collection variables
// You could use global or environment variables, up to you.
const startDate = pm.collectionVariables.get("startDate")
Re-setting the value on the Tests
// Loop through the results save the data and retrieve the next start date for the request
// After you have it
const startDate = pm.collectionVariables.set("startDate",variableWithDate)
// If you've reach the end you stop, if not you call the same request to loop
// nextPage is an example of a boolean that you've set before
if (nextPage) {
postman.setNextRequest("NAMEOFREQUEST")
} else
postman.setNextRequest(null)
}

Headers is treated as Data in spreadsheet query through JS

I am trying to read data from Spreadsheet using google visualization query. i am sending axios request to my spreadsheet. after getting response the output shows 1st column as data itself instead of headers. I am sending axios request to url.
** let url = https://docs.google.com/spreadsheets/d/${id}/gviz/tq?tqx=out:csv&tq=${encodedQuery}&gid=${gid} **
What do I need to change to get all the headers as it should be or all as the data also works fine. is there something wrong with the spreadsheet. I have deleted my sheet and recreated but the problem persists
After going through 7 hrs of mental blowing up I have solution for the question for i have posted. The reson behind the error was simply bad (empty) assignments in the sheets. Generally if the first item in the sheet is empty then this becomes bad assignment in array and the query fails to detect the comman type of data. So it takes the headers as data. To avoid this always populate the first set of data in the sheet to make sure the query can detect the type of data and treat headers as headers and not data.

Apollo pagination and cache-and-network fetch policy

The apollo docs suggest a way to implement the merge function in a field policy when implementing pagination logic.
merge(existing = [], incoming) {
return [...existing, ...incoming];
}
However, when I use 'cache-and-network' fetch policy for the query, that means that first it loads data from the cache, then it goes out to the network, and will append the existing list with the incoming data, so every item will exist in the cache twice, if the incoming data is the same as what was in the cache before.
What is the correct way to solve this? Can I differentiate between an initial load and a fetchmore request in the merge function? The merge function should obviously work differently for an initial fetch that should overwrite what we have loaded from the cache, and for a pagination fetch more.
In case anyone stumbled into this issue, solution as of Apollo 3 is:
fetchPolicy: 'cache-and-network',
nextFetchPolicy: 'cache-first',

How to build a model's custom RESTAdapter depending on route?

I'm very new to Ember.js, so still getting the fundamentals down. I have a model, let's call it dog, whose data is coming from an external API. The API only allows you to get big dogs and small dogs separately:
http://api.example.com/big/dogs
http://api.example.com/small/dogs
If I were to have big and small routes of my own—each of which would get the appropriate list of dogs—how could I customize my DogAdapter's buildURL method to put together the correct API call depending on the current route?
This is a very simplified example, please let me know if anything needs to be clarified.
I figured it out. As an example, my big route should return:
this.store.query( 'dog', { size: 'big' } )
and my DogAdapter should define something like:
buildUrl( model, id, snapshot, req, query ) {
return 'http://api.example.com/' + query.size + '/dogs'
}

REST and Filtering records

I currently have a .NET method that looks like this - GetUsers(Filter filter) and this is invoked from the client by sending a SOAP request. As you can probably guess, it takes a bunch of filters and returns a list of users that match those filters. The filters aren't too complicated, they're basically just a set of from date, to date, age, sex etc. and the set of filters I have at any point is static.
I was wondering what the RESTful way of doing this was. I'm guessing I'll have a Users resource. Will it be something like GET /Users?fromDate=11-1-2011&toDate=11-2-2011&age=&sex=M ? Is there a way to pass it a Filter without having to convert it into individual attributes?
I'm consuming this service from a mobile client, so I think the overhead of an extra request that actually creates a filter: POST filters is bad UX. Even if we do this, what does POST filters even mean? Is that supposed to create a filter record in the database? How would the server keep track of the filter that was just created if my sequence of requests is as follows?
POST /filters -- returns a filter
{
"from-date" : "11-1-2011",
"to-date" : "11-2-2011",
"age" : "",
"sex" : "M"
}
GET /Users?filter=filter_id
Apologies if the request came off as being a little confused. I am.
Thanks,
Teja
We are doing it just like you had it
GET /Users?fromDate=11-1-2011&toDate=11-2-2011&age=&sex=M
We have 9 querystring values.
I don't see any problem with that
The way I handle it is I do a POST with the body containing the parameters and then I return a redirect to a GET. What the GET URL looks like is completely up to the server. If you want to convert the filter into separate query params you can, or if you want to persist a filter and then add a query param that points to the saved filter that's ok too. The advantage is that you can change your mind at any time and the client doesn't care.
Also, because you are doing a GET you can take advantage of caching which should more than make up for doing the extra retquest.