How do I filter through subitem data in JSON API call? - json

I am writing a simple API call onto my page. The API is called and the data is filtered so it only displays certain items from the API.
Here is an example of the JSON:
{
"solutionName": "Example",
"solutionUrl": "https://example.com",
"metadata": {
"personas": "Digital Champions;End-user",
"businessFunctions": null
}
}
I am displaying the title of each item on my page like this:
<h2>${item.solutionName}</h2>
When I run a filter like this, it yields results just fine:
const filteredData = data.filter(item => item.metadata.solutionName.includes('example'));
However, I want to filter based on the metadata subitems. When I run a filter like this, I get an error:
const filteredData = data.filter(item => item.metadata.personas.includes('Champions'));
I get the console error "TypeError: Cannot read properties of undefined (reading 'includes')", only when I am trying to run an "includes" check through a metadata item. How can I resolve this so I can successfully filter through the subitems?

Related

Google Apps Script Web App: Uncaught TypeError: Cannot convert undefined or null to object

I am creating a Web App in Google Apps Script that have a server-side javascript file (Code.gs) and a client-side file (order-page-js.html). I am attempting to pull data from a spreadsheet, create an object, and send the object (which contains two key-value pairs, items and orders, both with two dimensional arrays as the values) from the server-side to the client-side so that it can populate data on the HTML web app . However, I keep getting this error:
Uncaught TypeError: Cannot convert undefined or null to object
at Function.values (<anonymous>)
at userCodeAppPanel:199:24
at Of (2515706220-mae_html_user_bin_i18n_mae_html_user.js:94:266)
at 2515706220-mae_html_user_bin_i18n_mae_html_user.js:25:132
at Ug.U (2515706220-mae_html_user_bin_i18n_mae_html_user.js:123:380)
at Bd (2515706220-mae_html_user_bin_i18n_mae_html_user.js:54:477)
at a (2515706220-mae_html_user_bin_i18n_mae_html_user.js:52:52)
Here is the server side code related to this issue:
function getData() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
let itemsWS = ss.getSheetByName('Items');
let items= itemsWS.getRange(2, 1, itemsWS.getLastRow()-1, itemsWS.getLastColumn()).getValues();
let ordersWS = ss.getSheetByName("Orders");
let orders= ordersWS.getRange(2, 1, ordersWS.getLastRow()-1, ordersWS.getLastColumn()).getValues();
let res = {};
res.items = items;
res.orders = orders;
return res;
Here is the client side showing where the error occurs. Line 199 (where the error occurs) is the menuItems = Object.values(res.items); line.
const order = new Order();
function sheetData(){
google.script.run.withSuccessHandler(function(res) {
menuItems = Object.values(res.items);
orders = res.orders;
order.menu = menuItems;
order.previousOrders = orders;
Ui.menu(order);
Ui.orderNumber(order);
}).getData();
}
sheetData();
I have been able to get the data from the spreadsheet without issue. I have been able to send just one of the key-value pairs (such as from the server-side to the client-side, but the object always has a value of null although I receive object when trying console.log(typeof(res));
When I Logger.log(res); on the server-side immediately before return res;, the object appears to have both key-value pairs with both values being the correct two-dimensional arrays. However, when I attempt to work with the object on the client-side, I receive the Uncaught TypeError: Cannot convert undefined or null to object error.

Azure Data Factory - REST API Call Pagination

I'm making a call for data in Data Factory and struggling to call the url in the "next_page" item.
This is an example of what the first API call returns:
{
"items": [
{
"title_one": "TTL-55924",
"id": "CPT-TTL-64577_TTL-55924",
"title_id": "TTL-64577"
},
{
"title_one": "TTL-69015",
"id": "CPT-TTL-79755_TTL-69015",
"title_id": "TTL-79755"
}
],
"next_page": "http://api.com/api/info?offset=5000&key=XXXxxxXXXxxx"
}
I'm not sure which options to use in the Pagination Rules of my Copy activity.
Currently I'm trying the option "AbsoluteURL" with the value "$['next_page']" but this just returns an error.
If your API response contains the next page URL property, then the “AbsoluteUrl“ pagination rule is the correct option to load the next page in the Azure data factory.
The supported values for pagination rules are mentioned in this MS document.
As mentioned in the example from the above document, Facebook Graph API returns the response as,
{
"data": [
…
…
],
"paging": {
…
…
},
"previous": "https://graph.facebook.com/me/albums?limit=25&before=NDMyNzQyODI3OTQw",
"next": "https://graph.facebook.com/me/albums?limit=25&after=MTAxNTExOTQ1MjAwNzI5NDE="
}
}
Note: Pagination value of a JSON path expression starts with “$”.
Your pagination in REST copy activity looks like this:
In your API, the pagination should look like
I have a similar issue. I am trying to copy shopify data from the rest API and was able to get the 1st page of data, however i cannot figure out how to set the pagination. THe pagination is coming in the header response like this:
I have it set to this but this returns an error:
ADF ERROR:
Failure happened on 'Source' side. ErrorCode=RestSourceCallFailed,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=The HttpStatusCode 404 indicates failure.
Request URL: https://joyfolie.myshopify.com/admin/api/2021-07/%3Chttps://joyfolie.myshopify.com/admin/api/2021-07/products.json?limit=50&page_info=eyJsYXN0X2lkIjo0NjI0ODcyMjEwNDkwLCJsYXN0X3ZhbHVlIjoiKk5FVyogQmFlIFNraXJ0IGluIE9jaHJlIiwiZGlyZWN0aW9uIjoibmV4dCJ9%3E;%20rel=%22next%22
Response payload:{"errors":"Not Found"},Source=Microsoft.DataTransfer.ClientLibrary,'
Source
Pipeline
Copy Shopify Products
THis is how the link looks in the response header
https://joyfolie.myshopify.com/admin/api/2022-01/products.json?limit=50&page_info=eyJsYXN0X2lkIjo0NjI0ODcyMjEwNDkwLCJsYXN0X3ZhbHVlIjoiKk5FVyogQmFlIFNraXJ0IGluIE9jaHJlIiwiZGlyZWN0aW9uIjoibmV4dCJ9; rel="next"

Getting [object][object] when trying to display data from api service

There are similar questions out there on StackOverflow but not exactly like mine.
When I check the Network tab in Inspector the data is being pulled from the api service. However, when I try to call it to the page I get [object][object].
Here's the structure of the data:
Object.widget.Value ... I would like to display the Value.
Here's how I am currently trying to call it:
{{i.widget}}
I've also tried json stringify and "| json" and those get me "undefined".
All other data that exists on the same level as widget is displaying fine and formatted the same. For some reason I can't pull widget's value.
Thanks for the help!
if this's what API return to us:
{name: "fox"}
in our component we can get it as:
data: any;
this.service.getData().subscribe((response) => {
this.data = response.body;
});
in our view if we put {{data}} it will return [object][object], you should set an property too in this case we have name which equal to fox, for example: {{data.name}};

Error while using filter in flutter for Listview

I am trying to filter the list with element data_code which is received by a Stateful widget, but I am getting the error as below description
Code
List list4= list2.where(widget.bomdatareceived[0]['data_items'][0]['data_code'].contains(widget.data_code));
ERROR
type 'bool' is not a subtype of type '(dynamic) => bool'
JSON Data
"data_items": [
{
"data_code": "61",
"data_name": "dat1",
"data_item": "327",
},
{
"data_code": "61",
"data_name": "dat4",
"data_item": "390",
},
{
"data_code": "65",
"data_name": "dat3",
"data_item": "1056",
}
]
The above JSON data is on the list, I want to implement a filter kind of thing in this ListView.builder, to enlist only those elements which have same data_code, I am not implementing any search bar kind of thing on the screen. I am receiving the value of data_code from the previous screen and want to build the list which has the same data_code .
Please guide me how to resolve this issue. I am new at the learning of flutter
In where method you need to use function which returns bool and its argument is each element of a list. So in your situation it should be something similar to:
var list4 = list2.where((item) => item.contains(widget.data_code));
I don't know how list2 looks like, so it's sample condition.

How do I display json get result using Wix Code?

I'm working with a non-profit cat shelter trying to update their website. They want to have a page that connects to their shelter manager software to display the available cats for adoption. Luckily, their shelter manager offers API calls to get the information I need from it.
They use Wix as their platform and are pretty set on keeping it as most of their volunteers know how to make easy adjustments to other pages. I researched and found Wix offers the ability to connect to the API using their fetch method.
Basically, I am trying to get a dynamic page to display a repeater that is populated from their json API Get method.
Currently, for the backend I have (URL to API removed for security):
import {fetch} from 'wix-fetch';
export function getdata(){
return fetch('URL to API Service', {method: 'get'})
.then( (httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
}
} );
}
On the page, this is where I think I am getting stuck:
import {getdata} from 'backend/fetchCats';
getdata()
.then(json => {
console.log(json);
var catData = json;
// static repeater data
$w.onReady(function () {
// handle creation of new repeated items
$w("#repeater1").onItemReady( ($item, itemData, index) => {
$item("#text23").text = itemData.ANIMALNAME;
} );
// set the repeater data, triggering the creation of new items
$w("#repeater1").data = catData;
} );
});
The above is giving me the error: Wix code SDK error: Each item in the items array must have a member named _id which contains a unique value identifying the item.
I know the JSON call has an ID field in it, but I am guessing Wix is expecting an _id field.
Am I just doing this wrong? Or am I missing something simple? I've spent a couple nights searching but can't really find a full example online that uses Wix's fetch method to get data via my HTTPS Get.
Thanks for any help!
You are doing fine.
You are getting the error from the line $w("#repeater1").data = catData;
which is the line used to set the items into the repeater. A repeater expects to have a _id member for each of the items, and your data quite probably does not have such an attribute.
I assume the API you are using, when returning an array, each item has some identifying attribute? if so, you can just do a simple transform like -
let catDataWithId = catData.map(item => {
item._id = item.<whatever id attribute>;
return item;
});
$w("#repeater1").data = catData;