Passing values from an API through another API discord.js - axios

So what trying to do is get some values I get from an API, pass onto an array to THEN pass it through another API and then add up the data it gets.
I already made this fetching it from 1 api, but I don't know how to fetch all the values from one api, pass it into an array, and fetch each value for each item.
let req1 = `https://inventory.roblox.com/v1/users/${imageURL}/assets/collectibles?sortOrder=Asc&limit=100`
let req2 = `https://users.roblox.com/v1/users/${imageURL}`
function getItems() {
return axios.get(req1)
}
function getUser() {
return axios.get(req2)
}
await Promise.all([getItems(), getUser(),getValue()])
.then(function(response){
let rap = response[0].data.data
let items = response[0].data.data.assetId
let itemarray = 0
let value = response[2].data.items[items array goes here][4]
let sum = 0
for(let i = 0; i < rap.length; i++) {sum += response[0].data.data[i].recentAveragePrice}
this is what I have so far. Any help will be appreciated. Thanks.
Edit:
Heres what req1 spits out:
{
"previousPageCursor": null,
"nextPageCursor": "49034821991_1_a887f8ff3a6b076aafd71c91a5a4a4fb",
"data": [
{
"userAssetId": 23726188,
"serialNumber": null,
"assetId": 7636350,
"name": "Supa Fly Cap",
"recentAveragePrice": 23535,
"originalPrice": null,
"assetStock": null,
"buildersClubMembershipType": 0
},
{
"userAssetId": 1329942875,
"serialNumber": 13717,
"assetId": 113325603,
"name": "Recycled Cardboard Shades",
"recentAveragePrice": 5703,
"originalPrice": 25,
"assetStock": 15000,
"buildersClubMembershipType": 0
},
```
req2 doesnt apply for this part of the code :p

Related

How do I get all pages of a paginated response in a Power Query query that also uses parameters?

I'm trying to get all pages of the API responses using Power Query Editor for Power BI Desktop, but have run into some problems getting the query to run.
I've used This tutorial as a starting point (but am open to suggestions).
The Problem
Currently, when I invoke this function from the table with the ext_id, to, and from parameters, I get an Expression.Error that The parameter is expected to be of type Text.Type or Binary.Type.
All I want to do is get all the pages of the query. The pages are available in the response at reviews.page.total.
I'm also trying to be as efficient as possible, as AppFollow uses a credit-based "payment" system for transacting with the API. Can someone help figure out where I've gone wrong?
My Current Code
(ext_id as text, from as text, to as text) =>
let
BaseURL = "https://api.appfollow.io/api/v2/reviews?",
token = "[redacted]",
Query = "ext_id=" & ext_id & "&from=" & from & "&to=" & to,
GetJson = (Url) =>
let
Options = [Headers=[Accept="application/json", #"X-AppFollow-API-Token"= token ]],
RawData = Web.Contents(Url, Options),
Json = Json.Document(RawData)
in Json,
GetPageCount = () =>
let Url = BaseURL & Query,
response = GetJson(Url),
toJson = Json.Document(response),
total = toJson[reviews]{0}[page][total]
in total,
GetPage = (Index) =>
let
Page = "&page=" & (Index),
Url = BaseURL & Query & Page,
Json = GetJson(Url),
Value = Json[reviews]
in Value,
PageCount = GetPageCount(),
PageIndicies = {0..PageCount -1},
Pages = List.Transform(PageIndicies, each GetPage(_)),
Results = List.Union(Pages),
#"Converted to Table" = Table.FromRecords(Results)
in
#"Converted to Table"
Sample Response
{
"query": "/api/reviews?cid=[cid-here]&ext_id=[ext-id-here&from=2023-01-01&to=2023-01-31&host=global4.appfollow.io&method=GET&real_ip=xxx.xxx.xxx.xx",
"reviews": {
"list": [
{
"data": "[removed data]"
}
],
"total": 286,
"page": {
"current": 1,
"total": 3,
"next": 2,
"prev": null
},
"ext_id": "ext-id-here",
"store": "as"
}
}
Error Message
Expression.Error: The parameter is expected to be of type Text.Type or Binary.Type.
Details:
query=/api/reviews?ext_id=[ext-id-here]&to=2023-01-31&from=2023-01-01&dev103=1&cid=[cid-here]&host=global4.appfollow.io&method=GET&real_ip=xxx.xx.xxx.xxx
reviews=[Record]
Try
Page = "&page=" & Text.From((Index)),

A Map related error in flutter which happens everytime I try to parse it

I have a map which contains two standard key and value pairs like
_body = {
"expected_time": "$Time",
"payment": "$payment",
"receiver" : {},
};
And another map named receiver inside it as you can see. Values are being passed to the receiver later using a for loop and the information is being added just fine.
for(int i=0; i<=n; i++)
{
_body['receiver'][i] = {
"receiver_name" : "abc",
};
}
The issue I'm facing is when trying to send this map to an api call via http.post
there jsonEncode(body) has been used to encode the map to send it. When sending those simple key value pairs I'm getting no error but when I'm trying to include the receiver field as well I'm getting the error.
Can anyone please tell me what I need to here? Thanks!
you are not making it in the right way, try this
var _body = {
"expected_time": "time",
"payment": "payment",
"receiver" : {},
};
for(int i=0; i<=3; i++) {
_body.addAll({
'receiver[$i]': {
"receiver_name": "abc",
}
});
}
print(_body);
and the output is like this
{expected_time: time, payment: payment, receiver: {}, receiver[0]: {receiver_name: abc}, receiver[1]: {receiver_name: abc}, receiver[2]: {receiver_name: abc}, receiver[3]: {receiver_name: abc}}
you can now encode it

Flutter : can't get all response body from get request

I have get request in Flutter app, when I test the request in postman I get all data, something like this :
{
"result":{
"name" : "somename",
"images":[
"test.jpg",
"test2.jpg"
],
"sizes":[
{
"id": 1,
"value" : 5
},
{
"id": 2,
"value" : 15
}
]
}
}
I call data and print them like this without using models:
var data = json.decode(response.body);
print(data['result']['name']);
print(data['result']['images']);
print(data['result']['sizes']);
it is print all things expect last one.
where must be the mistake?
Solved, by adding "?sizesView = true" to the link
final response = await http.get(path +'?sizesView = true'):
you should get the index of the last one because it is in a dictionary not a list do this:
print(data['result']['sizes'][0]['id']) // it will get the first index of the sizes list and then get the id key
or you can creat a model of list to get the indexes of your list

Getting Cannot read property in postman scripts when null found

I am getting an Error when running a script in the Postman Tests tab, When trying to check that a property is not null.
My JSON response:
{
"statusMessage": "Success",
"timeStamp": "2018-01-23 05:13:16.7",
"numberOfRecords": 7,
"parties": [
{
"shippingAddress": null,
"shippingDetails": null,
"paExpirationDate": "",
"historyDate": "01/22/2018",
"renewal": {
"renewalRx": "N",
"priorRxNumber": "",
"priorSB": "",
"priorFillNumber": ""
},
"noOfRefillingRemaining": "1",
"ndc": "00074-3799-06",
"rxId": "7004942",
"fillingNumber": "0"
},
{
"shippingAddress": {
"addressLine1": "2150 St",
"addressLine2": "Home Line 2",
"city": "Bronx",
"state": "NY",
"zipCode": "10453",
"addressSeqNumber": "1",
"medFacilityIndicator": "N"
}
}
]
}
My postman script is:
var jsonData = JSON.parse(responseBody);
var parties = jsonData.parties;
parties.forEach(function(data){
if(data.shippingAddress!==null && data.shippingAddress.addressLine1 !== null ){
postman.setEnvironmentVariable("addressLine1",data.shippingAddress.addressLine1);
}
I am getting the following error:
"Error running tests for results: TypeError: Cannot read property 'addressLine1' of null"
You could try this, I changed your code slightly but this would work:
var parties = pm.response.json().parties
for(i = 0; i < parties.length; i++) {
if(parties[i].shippingAddress !== null) {
pm.environment.set("addressLine1", parties[i].shippingAddress.addressLine1)
}
}
I tested this locally with the Schema that you provided and that it wrote 2150 St to my environment file.
The schema you posted doesn't seem to be a complete one, I think that the parties array has a shippingAddress property which is either null or it is an object containing the shippingAddress details - I might be wrong but I can't get my head around the data that you posted.
I don't think what you're searching on the in the if statement is correct and it wouldn't work the way you have it because if the first condition is null (like in your response data) it wouldn't ever meet the second condition because the object wouldn't be there and that shippingAddress.addressLine1 reference would always show that error.
Or you could use your code like this:
var jsonData = JSON.parse(responseBody)
var parties = jsonData.parties
parties.forEach(function(data) {
if(data.shippingAddress !== null) {
postman.setEnvironmentVariable("addressLine1",data.shippingAddress.addressLine1)
}
})

Backbone pagination

can anyone explain to me how this backbone.paginator example works?
https://github.com/backbone-paginator/backbone.paginator/blob/master/examples/request-paging/collections/PaginatedCollection.js
I see that the backend can be reached using the URL:
paginator_core: {
type: 'GET',
dataType: 'jsonp',
url: 'https://api.github.com/repos/twitter/bootstrap/issues?'
},
But what/where does this example pass the page number and amount of itmes to retreive from the backend? My backend is accessible through the following restfull url: and i cant figure out how the next page details are inserted in the url above...
www.test.com/getItems/{query}/{from}/{size}
Is this automatically inserted by the paginator plugin?
Just check internal implementation for fetch method
// map params except directions
var queryParams = this.mode == "client" ?
_pick(this.queryParams, "sortKey", "order") :
_omit(_pick(this.queryParams, _keys(PageableProto.queryParams)),
"directions");
var i, kvp, k, v, kvps = _pairs(queryParams), thisCopy = _clone(this);
for (i = 0; i < kvps.length; i++) {
kvp = kvps[i], k = kvp[0], v = kvp[1];
v = _isFunction(v) ? v.call(thisCopy) : v;
if (state[k] != null && v != null) {
data[v] = state[k];
}
}
request creates based on
queryParams: {
currentPage: "page",
pageSize: "per_page",
totalPages: "total_pages",
totalRecords: "total_entries",
sortKey: "sort_by",
order: "order",
directions: {
"-1": "asc",
"1": "desc"
}
},
property - thus current collection state mapps over setting from queryParams for generations url