Not Showing nested Json Data from Custom Api in FlatList in ReactNative - react-native

i tried several times to fetch data, but it is not showing anything in the app,
here is the code base for the fetching Api data.
it is console logging.
the data is console logging in the metro
but while trying to render in the flat List it is not showing anything,instead a blank page is displayed.
the data is a nested objects.
import React, {useEffect, useState} from 'react';
import {FlatList, SafeAreaView, Text, View} from 'react-native';
export default FoodProductsApi = () => {
const [data, setData] = useState([]);
const getFoodApi = () => {
fetch(
'url',
{
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
countryName: 'India',
deliveryPincode: '5600100',
categoryType: 'Food',
}),
},
)
.then(response => response.json())
.then(json => {
setData(json.foodProducts);
console.log(json.foodProducts.categories);
})
.catch(error => {
console.error(error);
});
};
useEffect(() => {
getFoodApi();
}, []);
const keyExtractor = () => item => item.id;
return (
<SafeAreaView>
<Text>Name</Text>
<FlatList
data={data.foodProducts}
keyExtractor={keyExtractor}
renderItem={index => (
<View style={{flex: 1}}>
{index.data.foodProducts.map((i, v) => {
<Text>{i.categoryName}</Text>;
})}
</View>
)}
/>
</SafeAreaView>
);
};
this is the json Data
{
"responseCode": "200",
"responseMessage": "Successfull",
"foodProducts": {
"hubId": "610299e303be56ca3924971e",
"categories": [
{
"id": "61028aff294f460012c9101e",
"categoryName": "Kalyani Biryani",
"rankOrder": 6,
"status": "ACTIVE",
"createDate": "2021-07-29T11:03:27.345+0000",
"createdBy": null,
"updatedDate": "2021-07-29T13:17:55.270+0000",
"updateBy": "60b12c9e637d050012a7cf6b",
"zohoCategoryId": "594850000000019627",
"foodCategoryImage": "",
"categoryType": "Food",
"foodProducts": [
{
"id": "6102aa6f03be56ca3924b8f9",
"zohoItemId": "594850000000022886",
"productName": "Kalyani Chicken Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B035",
"mrp": 500,
"discountedPrice": 400,
"rankOrder": 6,
"description": null,
"hsnCode": "5006096",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.059+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.059+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Chicken",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "58.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b900",
"zohoItemId": "594850000000022946",
"productName": "Kalyani Egg Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B037",
"mrp": 300,
"discountedPrice": 290,
"rankOrder": 6,
"description": null,
"hsnCode": "5006097",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.348+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.348+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Egg",
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "56.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b907",
"zohoItemId": "594850000000022915",
"productName": "Kalyani Mutton Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B036",
"mrp": 200,
"discountedPrice": 160,
"rankOrder": 6,
"description": null,
"hsnCode": "5006096",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.652+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.652+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Mutton",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "52.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b910",
"zohoItemId": "594850000000022977",
"productName": "Kalyani Paneer Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Veg",
"sku": "B038",
"mrp": 200,
"discountedPrice": 160,
"rankOrder": 12,
"description": null,
"hsnCode": "5006978",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.938+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.938+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": null,
"spiceLevel": "1",
"categoryType": "Food",
"availableStock": "51.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7603be56ca3924b992",
"zohoItemId": "594850000000022762",
"productName": "Thalassery Chicken Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B031",
"mrp": 400,
"discountedPrice": 320,
"rankOrder": 17,
"description": null,
"hsnCode": "5006990",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:18.173+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:18.173+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Chicken",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "128.000000",
"isFavorite": null,
"hubId": null
}
]
},
{
"id": "61028aa8294f460012c9101b",
"categoryName": "Bombay Biryani",
"rankOrder": 23,
"status": "ACTIVE",
"createDate": "2021-07-29T11:02:00.541+0000",
"createdBy": null,
"updatedDate": "2021-07-29T13:18:27.081+0000",
"updateBy": "60b12c9e637d050012a7cf6b",
"zohoCategoryId": "594850000000019605",
"foodCategoryImage": "",
"categoryType": "Food",
"foodProducts": [
{
"id": "6102aa6803be56ca3924b846",
"zohoItemId": "594850000000022576",
"productName": "Bombay Paneer Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Veg",
"sku": "B024",
"mrp": 400,
"discountedPrice": 360,
"rankOrder": 10,
"description": null,
"hsnCode": "50090994",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:03.459+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:03.459+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": null,
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "130.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa6703be56ca3924b832",
"zohoItemId": "594850000000022607",
"productName": "Bomaby Fish Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Non Veg",
"sku": "B025",
"mrp": 250,
"discountedPrice": 170,
"rankOrder": 11,
"description": null,
"hsnCode": "50090995",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:02.305+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:02.305+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Sea Food",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "145.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa6803be56ca3924b83d",
"zohoItemId": "594850000000022638",
"productName": "Bombay Egg Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Non Veg",
"sku": "B026",
"mrp": 240,
"discountedPrice": 210,
"rankOrder": 16,
"description": null,
"hsnCode": "5009099",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:02.885+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:02.885+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Egg",
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "-141.000000",
"isFavorite": null,
"hubId": null
}
]
},

Hope this Solves your Problem,
import React from 'react';
import {
SafeAreaView,
StyleSheet,
View,
Text,
FlatList
} from 'react-native';
const App = () => {
const [data, setData] = useState([]);
useEffect(() => {
getFoodApi();
}, []);
function getFoodApi()
{
setData({
"foodProducts": {
"hubId": "610299e303be56ca3924971e",
"categories": [
{
"id": "61028aff294f460012c9101e",
"categoryName": "Kalyani Biryani",
"rankOrder": 6,
"status": "ACTIVE",
"createDate": "2021-07-29T11:03:27.345+0000",
"createdBy": null,
"updatedDate": "2021-07-29T13:17:55.270+0000",
"updateBy": "60b12c9e637d050012a7cf6b",
"zohoCategoryId": "594850000000019627",
"foodCategoryImage": "",
"categoryType": "Food",
"foodProducts": [
{
"id": "6102aa6f03be56ca3924b8f9",
"zohoItemId": "594850000000022886",
"productName": "Kalyani Chicken Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B035",
"mrp": 500,
"discountedPrice": 400,
"rankOrder": 6,
"description": null,
"hsnCode": "5006096",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.059+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.059+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Chicken",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "58.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b900",
"zohoItemId": "594850000000022946",
"productName": "Kalyani Egg Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B037",
"mrp": 300,
"discountedPrice": 290,
"rankOrder": 6,
"description": null,
"hsnCode": "5006097",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.348+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.348+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Egg",
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "56.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b907",
"zohoItemId": "594850000000022915",
"productName": "Kalyani Mutton Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B036",
"mrp": 200,
"discountedPrice": 160,
"rankOrder": 6,
"description": null,
"hsnCode": "5006096",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.652+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.652+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Mutton",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "52.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7003be56ca3924b910",
"zohoItemId": "594850000000022977",
"productName": "Kalyani Paneer Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Veg",
"sku": "B038",
"mrp": 200,
"discountedPrice": 160,
"rankOrder": 12,
"description": null,
"hsnCode": "5006978",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:11.938+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:11.938+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": null,
"spiceLevel": "1",
"categoryType": "Food",
"availableStock": "51.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa7603be56ca3924b992",
"zohoItemId": "594850000000022762",
"productName": "Thalassery Chicken Biryani",
"productImage": null,
"categoryId": "594850000000019627",
"vegNonVegFlag": "Non Veg",
"sku": "B031",
"mrp": 400,
"discountedPrice": 320,
"rankOrder": 17,
"description": null,
"hsnCode": "5006990",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:18.173+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:18.173+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Chicken",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "128.000000",
"isFavorite": null,
"hubId": null
}
]//food products[0]
}, //categories[0]
{
"id": "61028aa8294f460012c9101b",
"categoryName": "Bombay Biryani",
"rankOrder": 23,
"status": "ACTIVE",
"createDate": "2021-07-29T11:02:00.541+0000",
"createdBy": null,
"updatedDate": "2021-07-29T13:18:27.081+0000",
"updateBy": "60b12c9e637d050012a7cf6b",
"zohoCategoryId": "594850000000019605",
"foodCategoryImage": "",
"categoryType": "Food",
"foodProducts": [
{
"id": "6102aa6803be56ca3924b846",
"zohoItemId": "594850000000022576",
"productName": "Bombay Paneer Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Veg",
"sku": "B024",
"mrp": 400,
"discountedPrice": 360,
"rankOrder": 10,
"description": null,
"hsnCode": "50090994",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:03.459+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:03.459+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": null,
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "130.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa6703be56ca3924b832",
"zohoItemId": "594850000000022607",
"productName": "Bomaby Fish Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Non Veg",
"sku": "B025",
"mrp": 250,
"discountedPrice": 170,
"rankOrder": 11,
"description": null,
"hsnCode": "50090995",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:02.305+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:02.305+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Sea Food",
"spiceLevel": "2",
"categoryType": "Food",
"availableStock": "145.000000",
"isFavorite": null,
"hubId": null
},
{
"id": "6102aa6803be56ca3924b83d",
"zohoItemId": "594850000000022638",
"productName": "Bombay Egg Biryani",
"productImage": null,
"categoryId": "594850000000019605",
"vegNonVegFlag": "Non Veg",
"sku": "B026",
"mrp": 240,
"discountedPrice": 210,
"rankOrder": 16,
"description": null,
"hsnCode": "5009099",
"gstPercentageInter": "12",
"gstPercentageIntra": "12",
"status": "ACTIVE",
"createdDate": "2021-08-11T07:51:02.885+0000",
"createdBy": "Zoho Sync Script",
"updatedDate": "2021-08-11T07:51:02.885+0000",
"updatedBy": "Zoho Sync Script",
"nonVegType": "Egg",
"spiceLevel": "3",
"categoryType": "Food",
"availableStock": "-141.000000",
"isFavorite": null,
"hubId": null
}
]
}
]//categories
}//foodApi
})
}
return (
<SafeAreaView style={{flex:1}}>
<Text>Name</Text>
<FlatList
style={{flex:1}}
data={data.foodProducts.categories}
keyExtractor={(item,index)=>index.toString()}
renderItem={({ item, index }) => {
return (
<View style={{flex: 1}}>
<Text> categoreyname {item.categoryName}</Text>
{item.foodProducts.map(ele => {
return (
<Text style={{ paddingLeft: 5 }}> productName { ele.productName}</Text>
)
})}
</View>
)
}}
/>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
});
export default App;

Flatlist will loop only array of object . in your code you have tried to loop objects (data.foodProducts).
Replace data={data.foodProducts} to data={data.foodproducts.categories}. Now it will loop, because its an array of objects.
Array of objects will be similar to this [{name:"React",age:5}]. This will be looped by flatlist
Objects will be similar to this {name:"react",age:5}. This will not looped by flatlist.
You can check whether data is an array or object using console.log(typeof data.foodproducts).

Related

Display data from an Api in the V-CALENDAR Vuetify Vuejs

I have the following data coming from my api:
[
{
"id": 1,
"start": "2020-12-24 01:00",
"end": "2020-12-24 01:30",
"comments": null,
"createdAt": "2020-12-24T19:37:52.699Z",
"updatedAt": "2020-12-24T19:37:52.699Z",
"clientId": 1,
"employeeId": null,
"serviceId": null,
"appointmentStatusId": null,
"tenantId": 1,
"employee": null,
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 3,
"start": "2020-12-24 21:15",
"end": "2020-12-24 22:00",
"comments": null,
"createdAt": "2020-12-24T19:45:03.854Z",
"updatedAt": "2020-12-24T19:45:03.854Z",
"clientId": 1,
"employeeId": 1,
"serviceId": null,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 2,
"start": "2020-12-24 01:00",
"end": "2020-12-24 02:00",
"comments": null,
"createdAt": "2020-12-24T19:39:19.184Z",
"updatedAt": "2020-12-24T19:39:19.184Z",
"clientId": 1,
"employeeId": 1,
"serviceId": null,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 13,
"start": "2020-12-25 06:00",
"end": "2020-12-25 07:00",
"comments": "Fuck you",
"createdAt": "2020-12-25T16:24:10.893Z",
"updatedAt": "2020-12-25T16:24:10.893Z",
"clientId": 1,
"employeeId": 2,
"serviceId": 1,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Margareth",
"lastName": "Martins"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 14,
"start": "2020-12-25 01:00",
"end": "2020-12-25 06:00",
"comments": null,
"createdAt": "2020-12-25T22:08:40.878Z",
"updatedAt": "2020-12-25T22:08:40.878Z",
"clientId": 1,
"employeeId": 1,
"serviceId": 1,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 15,
"start": "2020-12-26 08:30",
"end": "2020-12-26 09:00",
"comments": null,
"createdAt": "2020-12-25T22:52:31.439Z",
"updatedAt": "2020-12-25T22:52:31.439Z",
"clientId": 1,
"employeeId": 1,
"serviceId": 1,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 10,
"start": "2020-12-23 09:00",
"end": "2020-12-23 09:30",
"comments": "é fodauuuuuuu",
"createdAt": "2020-12-25T15:12:20.790Z",
"updatedAt": "2020-12-25T15:12:20.790Z",
"clientId": 1,
"employeeId": null,
"serviceId": 1,
"appointmentStatusId": null,
"tenantId": 1,
"employee": null,
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 11,
"start": "2020-12-23 09:00",
"end": "2020-12-23 12:00",
"comments": "é fodauuuuuuu",
"createdAt": "2020-12-25T15:12:44.161Z",
"updatedAt": "2020-12-25T15:12:44.161Z",
"clientId": 1,
"employeeId": 1,
"serviceId": 1,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 4,
"start": "2020-12-25 01:00",
"end": "2020-12-25 05:00",
"comments": null,
"createdAt": "2020-12-25T02:32:32.574Z",
"updatedAt": "2020-12-25T02:32:32.574Z",
"clientId": 1,
"employeeId": 1,
"serviceId": null,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 5,
"start": "2020-12-24 01:00",
"end": "2020-12-24 03:00",
"comments": "ghhhhhh",
"createdAt": "2020-12-25T02:36:52.243Z",
"updatedAt": "2020-12-25T02:36:52.243Z",
"clientId": 1,
"employeeId": 1,
"serviceId": null,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 6,
"start": "2020-12-25 01:15",
"end": "2020-12-25 02:00",
"comments": null,
"createdAt": "2020-12-25T02:38:22.711Z",
"updatedAt": "2020-12-25T02:38:22.711Z",
"clientId": 1,
"employeeId": 1,
"serviceId": null,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 7,
"start": "2020-12-25 00:15",
"end": "2020-12-25 03:00",
"comments": "treeeeee",
"createdAt": "2020-12-25T14:54:51.766Z",
"updatedAt": "2020-12-25T14:54:51.766Z",
"clientId": 1,
"employeeId": 1,
"serviceId": null,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 8,
"start": "2020-12-25 04:00",
"end": "2020-12-25 06:00",
"comments": null,
"createdAt": "2020-12-25T15:02:54.737Z",
"updatedAt": "2020-12-25T15:02:54.737Z",
"clientId": 1,
"employeeId": 1,
"serviceId": null,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
},
{
"id": 12,
"start": "2020-12-31 19:30",
"end": "2020-12-31 21:00",
"comments": "Agora foi",
"createdAt": "2020-12-25T15:25:40.233Z",
"updatedAt": "2020-12-25T15:25:40.233Z",
"clientId": 1,
"employeeId": 1,
"serviceId": 1,
"appointmentStatusId": null,
"tenantId": 1,
"employee": {
"firstName": "Aline",
"lastName": "Magalhães"
},
"client": {
"firstName": "Tamires",
"lastName": "Almeida"
}
}
]
I need to present only some of this data in the V-Calendar vuetify and according to its documentation it would be for example:
{
name: 'name'
start: '0000-00-00 00:00'
end: '0000-00-00 00:00'
}
To reach this structure I have the following code snippet in my .Vue:
created () {
this.initialize()
},
methods: {
initialize () {
// request Events
axios.get('http://192.168.15.11:3000/events')
.then((response) => {
this.events = response.data
for (const item of this.events) {
const name = item.client.firstName + ' ' + item.client.lastName
const start = item.start
const end = item.end
const items = { name, start, end }
this.events = this.items
console.log(items);
}
})
.catch((error) => {
console.log(error.response);
})
},
My console gives this feedback with the right format I need but in the calendar there is no event:
The V-Calendar excerpt:
<v-calendar
ref="calendar"
v-model="focus"
color="primary"
locale="pt-br"
:events="events"
:event-color="getEventColor"
:type="type"
#click:event="showEvent"
#click:more="viewDay"
#click:date="viewDay"
>
</v-calendar>
data: () => ({
events []
}),
Where can I be wrong, could someone help me?
Great work on providing a good context for your problem. V-calendar wants events to be an array, not a single object.
Maybe try something like this:
this.events = [];
axios.get('http://192.168.15.11:3000/events')
.then((response) => {
const events = response.data
for (const item of events) {
const name = item.client.firstName + ' ' + item.client.lastName
const start = item.start
const end = item.end
this.events.push({ name, start, end })
}
})

CosmosDB GeoSpatial Points Invalid

I'm using Azure's cosmos DB, and testing via the sqlquery in the Azure portal. Some points in my collection are valid, some are not. I am unable to tell from the GeoJSON spec if I am missing requirements. All my points pass the geojsonlint test: https://geojsonlint.com/
What could be causing invalid points? The locations are setup the same as far as I can tell.
My Query:
SELECT *
FROM events1 e
WHERE ST_ISVALID(e.location)
Running the query returns that these are valid:
[
{
"id": "b4b49b65-dfad-40f3-943b-753553507d2c",
"name": "OG Olympics",
"location": {
"type": "Point",
"coordinates": [
41.900697426935544,
12.480266913771628
]
},
"events": "Hockey",
"time": "00:00:00",
"recurring": null,
"date": null,
"difficulty": "Expert",
"ages": "Senior",
"admin": null,
"private": null,
"_rid": "Maw1AIaRiRoHAAAAAAAAAA==",
"_self": "dbs/Maw1AA==/colls/Maw1AIaRiRo=/docs/Maw1AIaRiRoHAAAAAAAAAA==/",
"_etag": "\"11003fb9-0000-0700-0000-5f2f15cf0000\"",
"_attachments": "attachments/",
"_ts": 1596921295
},
{
"id": "f2d063e3-5654-475d-8e97-7412dc77fcfb",
"name": "Test Event DenverCC",
"location": {
"type": "Point",
"coordinates": [
100.2093,
-15.868
]
},
"events": "Basketball",
"time": "18:00:00",
"recurring": null,
"date": null,
"difficulty": "Intermediate",
"ages": "Senior",
"admin": null,
"private": null,
"_rid": "Maw1AIaRiRoJAAAAAAAAAA==",
"_self": "dbs/Maw1AA==/colls/Maw1AIaRiRo=/docs/Maw1AIaRiRoJAAAAAAAAAA==/",
"_etag": "\"1300a79d-0000-0700-0000-5f304fc80000\"",
"_attachments": "attachments/",
"_ts": 1597001672
},
{
"id": "10000",
"name": "OG Olympics 2",
"location": {
"type": "Point",
"coordinates": [
41.000697426935545,
-12.080266913771627
]
},
"events": "Hockey",
"time": "00:00:00",
"recurring": null,
"date": null,
"difficulty": "Expert",
"ages": "Senior",
"admin": null,
"private": null,
"_rid": "Maw1AIaRiRoKAAAAAAAAAA==",
"_self": "dbs/Maw1AA==/colls/Maw1AIaRiRo=/docs/Maw1AIaRiRoKAAAAAAAAAA==/",
"_etag": "\"13003499-0000-0700-0000-5f304d580000\"",
"_attachments": "attachments/",
"_ts": 1597001048
}
]
But it returns that these are invalid:
{
"id": "1000",
"name": "Sunday Morning Hockey",
"location": {
"type": "Point",
"coordinates": [
39,
-105
]
},
"events": "hockey",
"time": "09:00",
"recurring": "true",
"date": "2020-08-02",
"difficulty": "all levels",
"ages": "all ages",
"admin": "1000",
"private": "false",
"_rid": "Maw1AIaRiRoBAAAAAAAAAA==",
"_self": "dbs/Maw1AA==/colls/Maw1AIaRiRo=/docs/Maw1AIaRiRoBAAAAAAAAAA==/",
"_etag": "\"13008c9f-0000-0700-0000-5f3050d70000\"",
"_attachments": "attachments/",
"_ts": 1597001943
}
{
"id": "9f373e04-0cfc-4121-927d-a6256dbe06c6",
"name": "test1",
"location": {
"type": "Point",
"coordinates": [
39.731441899363105,
-104.98381230980158
]
},
"events": "Basketball",
"time": "00:00:00",
"recurring": null,
"date": null,
"difficulty": "Expert",
"ages": "Adult",
"admin": null,
"private": null,
"_rid": "Maw1AIaRiRoLAAAAAAAAAA==",
"_self": "dbs/Maw1AA==/colls/Maw1AIaRiRo=/docs/Maw1AIaRiRoLAAAAAAAAAA==/",
"_etag": "\"13005999-0000-0700-0000-5f304d760000\"",
"_attachments": "attachments/",
"_ts": 1597001078
}
{
"id": "be01bc12-d28e-4368-b6de-0f3e84dbe13c",
"name": "test2",
"location": {
"type": "Point",
"coordinates": [
39.72082849205111,
-104.98461395502092
]
},
"events": "Hockey",
"time": "00:00:00",
"recurring": null,
"date": null,
"difficulty": "Expert",
"ages": "Adult",
"admin": null,
"private": null,
"_rid": "Maw1AIaRiRoMAAAAAAAAAA==",
"_self": "dbs/Maw1AA==/colls/Maw1AIaRiRo=/docs/Maw1AIaRiRoMAAAAAAAAAA==/",
"_etag": "\"1300219a-0000-0700-0000-5f304de10000\"",
"_attachments": "attachments/",
"_ts": 1597001185
}
Took a while to realize, but GeoJSON expects flipped coordinates in the Point.
So while Maps return me a point type with [ latitude, longitude ]. GeoJSON expects [longitude, latitude]

How to Access Nested object inside Nested Array JSON data on Screen in React-Native

I have an array of Data objects that contain another array of Attendance and I just want to access the all 30 day data from attendances array.I am trying to get date,chechIn,checkOut and totalHoure data of 30 days from attendances array.Here is my JSON API data.Please check my code too.
{
"message": "30 day data",
"data": [
{
"id": 2,
"addEmployee": {
"firstName": "Mohd"
},
"attendances": [
{
"id": 111,
"checkIn": "2020-03-24T06:01:26.000Z",
"checkOut": null,
"totalHours": null,
"date": "2020-03-24",
"status": "present",
"createdAt": "2020-03-24T06:01:26.000Z",
"updatedAt": "2020-03-24T06:01:26.000Z",
"userId": 2
},
{
"id": 132,
"checkIn": null,
"checkOut": null,
"totalHours": "0",
"date": "2020-03-25",
"status": "absent",
"createdAt": "2020-03-25T13:00:00.000Z",
"updatedAt": "2020-03-25T13:00:00.000Z",
"userId": 2
},
{
"id": 152,
"checkIn": null,
"checkOut": null,
"totalHours": "0",
"date": "2020-03-26",
"status": "absent",
"createdAt": "2020-03-26T13:00:00.000Z",
"updatedAt": "2020-03-26T13:00:00.000Z",
"userId": 2
},
{
"id": 173,
"checkIn": null,
"checkOut": null,
"totalHours": "0",
"date": "2020-03-27",
"status": "absent",
"createdAt": "2020-03-27T13:00:00.000Z",
"updatedAt": "2020-03-27T13:00:00.000Z",
"userId": 2
},
{
"id": 193,
"checkIn": null,
"checkOut": null,
"totalHours": "0",
"date": "2020-03-30",
"status": "absent",
"createdAt": "2020-03-30T13:00:00.000Z",
"updatedAt": "2020-03-30T13:00:00.000Z",
"userId": 2
},
{
"id": 216,
"checkIn": null,
"checkOut": null,
"totalHours": "0",
"date": "2020-03-31",
"status": "absent",
"createdAt": "2020-03-31T13:00:00.000Z",
"updatedAt": "2020-03-31T13:00:00.000Z",
"userId": 2
},
{
"id": 338,
"checkIn": null,
"checkOut": null,
"totalHours": "0",
"date": "2020-04-06",
"status": "absent",
"createdAt": "2020-04-06T13:57:30.000Z",
"updatedAt": "2020-04-06T13:57:30.000Z",
"userId": 2
},
{
"id": 372,
"checkIn": null,
"checkOut": null,
"totalHours": "0",
"date": "2020-04-07",
"status": "absent",
"createdAt": "2020-04-07T13:57:30.000Z",
"updatedAt": "2020-04-07T13:57:30.000Z",
"userId": 2
},
{
"id": 406,
"checkIn": null,
"checkOut": "2020-04-09T07:38:22.000Z",
"totalHours": "NaN:NaN",
"date": "2020-04-09",
"status": "present",
"createdAt": "2020-04-08T13:57:30.000Z",
"updatedAt": "2020-04-09T07:38:22.000Z",
"userId": 2
},
{
"id": 441,
"checkIn": "2020-04-09T07:38:25.000Z",
"checkOut": null,
"totalHours": null,
"date": "2020-04-09",
"status": "present",
"createdAt": "2020-04-09T07:38:25.000Z",
"updatedAt": "2020-04-09T07:38:25.000Z",
"userId": 2
},
{
"id": 528,
"checkIn": "2020-04-14T07:27:20.000Z",
"checkOut": null,
"totalHours": null,
"date": "2020-04-14",
"status": "present",
"createdAt": "2020-04-14T07:27:20.000Z",
"updatedAt": "2020-04-14T07:27:20.000Z",
"userId": 2
},
{
"id": 522,
"checkIn": "2020-04-14T07:27:18.000Z",
"checkOut": null,
"totalHours": null,
"date": "2020-04-14",
"status": "present",
"createdAt": "2020-04-14T07:27:18.000Z",
"updatedAt": "2020-04-14T07:27:18.000Z",
"userId": 2
},
{
"id": 535,
"checkIn": "2020-04-14T07:27:25.000Z",
"checkOut": "2020-04-14T07:27:31.000Z",
"totalHours": "0:0",
"date": "2020-04-14",
"status": "present",
"createdAt": "2020-04-14T07:27:25.000Z",
"updatedAt": "2020-04-14T07:27:31.000Z",
"userId": 2
},
{
"id": 516,
"checkIn": "2020-04-14T07:27:17.000Z",
"checkOut": null,
"totalHours": null,
"date": "2020-04-14",
"status": "present",
"createdAt": "2020-04-14T07:27:17.000Z",
"updatedAt": "2020-04-14T07:27:17.000Z",
"userId": 2
},
{
"id": 529,
"checkIn": "2020-04-14T07:27:20.000Z",
"checkOut": null,
"totalHours": null,
"date": "2020-04-14",
"status": "present",
"createdAt": "2020-04-14T07:27:20.000Z",
"updatedAt": "2020-04-14T07:27:20.000Z",
"userId": 2
},
{
"id": 523,
"checkIn": "2020-04-14T07:27:18.000Z",
"checkOut": null,
"totalHours": null,
"date": "2020-04-14",
"status": "present",
"createdAt": "2020-04-14T07:27:18.000Z",
"updatedAt": "2020-04-14T07:27:18.000Z",
"userId": 2
},
{
"id": 537,
"checkIn": "2020-04-14T09:42:31.000Z",
"checkOut": "2020-04-14T09:52:58.000Z",
"totalHours": "0:10",
"date": "2020-04-14",
"status": "present",
"createdAt": "2020-04-14T09:42:31.000Z",
"updatedAt": "2020-04-14T09:52:58.000Z",
"userId": 2
},
{
"id": 517,
"checkIn": "2020-04-14T07:27:17.000Z",
"checkOut": null,
"totalHours": null,
"date": "2020-04-14",
"status": "present",
"createdAt": "2020-04-14T07:27:17.000Z",
"updatedAt": "2020-04-14T07:27:17.000Z",
"userId": 2
},
{
"id": 530,
"checkIn": "2020-04-14T07:27:20.000Z",
"checkOut": null,
"totalHours": null,
"date": "2020-04-14",
"status": "present",
"createdAt": "2020-04-14T07:27:20.000Z",
"updatedAt": "2020-04-14T07:27:20.000Z",
"userId": 2
},
{
"id": 524,
"checkIn": "2020-04-14T07:27:19.000Z",
"checkOut": null,
"totalHours": null,
"date": "2020-04-14",
"status": "present",
"createdAt": "2020-04-14T07:27:19.000Z",
"updatedAt": "2020-04-14T07:27:19.000Z",
"userId": 2
},
{
"id": 518,
"checkIn": "2020-04-14T07:27:17.000Z",
"checkOut": null,
"totalHours": null,
"date": "2020-04-14",
"status": "present",
"createdAt": "2020-04-14T07:27:17.000Z",
"updatedAt": "2020-04-14T07:27:17.000Z",
"userId": 2
},
{
"id": 531,
"checkIn": "2020-04-14T07:27:21.000Z",
"checkOut": null,
"totalHours": null,
"date": "2020-04-14",
"status": "present",
"createdAt": "2020-04-14T07:27:21.000Z",
"updatedAt": "2020-04-14T07:27:21.000Z",
"userId": 2
},
{
"id": 525,
"checkIn": "2020-04-14T07:27:19.000Z",
"checkOut": null,
"totalHours": null,
"date": "2020-04-14",
"status": "present",
"createdAt": "2020-04-14T07:27:19.000Z",
"updatedAt": "2020-04-14T07:27:19.000Z",
"userId": 2
},
{
"id": 519,
"checkIn": "2020-04-14T07:27:17.000Z",
"checkOut": null,
"totalHours": null,
"date": "2020-04-14",
"status": "present",
"createdAt": "2020-04-14T07:27:17.000Z",
"updatedAt": "2020-04-14T07:27:17.000Z",
"userId": 2
},
{
"id": 532,
"checkIn": "2020-04-14T07:27:22.000Z",
"checkOut": "2020-04-14T07:27:22.000Z",
"totalHours": "0:0",
"date": "2020-04-14",
"status": "present",
"createdAt": "2020-04-14T07:27:22.000Z",
"updatedAt": "2020-04-14T07:27:22.000Z",
"userId": 2
},
{
"id": 478,
"checkIn": null,
"checkOut": "2020-04-14T07:27:12.000Z",
"totalHours": "NaN:NaN",
"date": "2020-04-14",
"status": "present",
"createdAt": "2020-04-10T13:57:30.000Z",
"updatedAt": "2020-04-14T07:27:12.000Z",
"userId": 2
},
]
}
],
"status": 1
}
With the help of this code I am getting only one day of data instead of 30 days.Here is my code.
componentDidMount() {
const url = 'http://104.197.28.169:3000/monthlyAdminData/10' ;
fetch(url)
.then(response => response.json())
.then((responseJson) => {
console.log("aagiyo" ,responseJson)
this.setState({
dataSource: responseJson.data,
isLoading: false,
})
})
.catch(error => console.log(error))
}
renderItem = ({ item}) => {
return (
<View style={styles.firstV1}>
<View style={styles.heading}>
<Text style={{ fontSize: 15,}}>{item.addEmployee.firstName }</Text>
</View>
<View style={styles.heading}>
<Text style={{ fontSize: 15}}>{item.attendances.length >0 ? item.attendances[0].date : null}
</Text>
</View>
<View style={styles.heading}>
<Text style={{ fontSize: 15}}> {item.attendances.length >0 ?item.attendances[0].checkIn :
null}</Text>
</View>
<View style={styles.heading}>
<Text style={{ fontSize: 15,}}>{item.attendances.length >0 ? item.attendances[0].checkOut :
null }</Text>
</View>
<View style={styles.heading}>
<Text style={{ fontSize: 15}}>{item.attendances.length >0 ? item.attendances[0].totalHours :
null }</Text>
</View>
</View>
)
}
   
You need to include the map function inside, I had worked on your code change your render function like this:
import React from 'react';
import {View, FlatList, Text} from 'react-native';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
data:[
{
"id": 2,
"addEmployee": {
"firstName": "Mohd"
},
"attendances": [
{
//Your data
}
]
},
{
"id": 21,
"addEmployee": {
"firstName": "Narayan"
},
"attendances": [
{
"id": 617,
"checkIn": "2020-04-17T05:20:45.000Z",
"checkOut": "2020-04-17T05:21:22.000Z",
"totalHours": "0:0",
"date": "2020-04-17",
"status": "present",
"createdAt": "2020-04-17T05:20:45.000Z",
"updatedAt": "2020-04-17T05:21:22.000Z",
"userId": 21
},
]
},
{
"id": 20,
"addEmployee": {
"firstName": "Himanshu"
},
"attendances": []
},
],
};
}
render() {
return (
<FlatList
data={this.state.data}
renderItem={({ item }) =>
{
return(
<View style={{alignItems:"center",justifyContent:"center",marginTop:50}}>
<Text style={{fontWeight:"bold",fontSize:18}}>Attendance of {item.addEmployee.firstName}</Text>
{ item.attendances.length > 0 ?
item.attendances.map((item, key) =>
{
return(
<View>
<View>
<Text style={{ fontSize: 15, fontWeight:"bold",marginLeft:"35%" }}>Day{key+1}</Text>
</View>
<View
style={{
borderBottomColor: 'black',
borderBottomWidth: 1,
}}
/>
<View style={{flexDirection:"row"}}>
<Text style={{fontWeight:"bold",width:"40%"}}>Check In :</Text>
<Text style={{ fontSize: 15, width:"50%"}}>{item.checkIn}</Text>
</View>
<View style={{flexDirection:"row"}}>
<Text style={{fontWeight:"bold",width:"40%"}}>Check Out :</Text>
<Text style={{ fontSize: 15, width:"50%"}}>{item.checkOut}</Text>
</View>
<View style={{flexDirection:"row"}}>
<Text style={{fontWeight:"bold",width:"40%"}}>Total Hours :</Text>
<Text style={{ fontSize: 15, width:"50%"}}>{item.totalHours}</Text>
</View>
</View>
)
}) : null
}
</View>
)
}
}
/>
);
}
}
Hope this helps!

Shopify find order ID in hook

I need to connect some external service to the Shopify store. I've set up the hook on Order creation event, I can receive it but I didn't find information about what incoming data means. I mean I need to store order_id in order to be able to control it. I'm receiving test hook that contains field named order_number. Can anyone confirm that this field is exact order ID? Also I'm receiving in the hook id field but I guess that field is hook_id, not order_id
If you already created webhook for Order creation then when order will be created, you will receive JSON with order object. This object has id property
Example of this JSON:
{
"id": 820982911946154500,
"email": "jon#doe.ca",
"closed_at": null,
"created_at": "2017-11-29T05:57:26-05:00",
"updated_at": "2017-11-29T05:57:26-05:00",
"number": 234,
"note": null,
"token": "123456abcd",
"gateway": null,
"test": true,
"total_price": "793.50",
"subtotal_price": "783.50",
"total_weight": 0,
"total_tax": "0.00",
"taxes_included": false,
"currency": "USD",
"financial_status": "voided",
"confirmed": false,
"total_discounts": "5.00",
"total_line_items_price": "788.50",
"cart_token": null,
"buyer_accepts_marketing": true,
"name": "#9999",
"referring_site": null,
"landing_site": null,
"cancelled_at": "2017-11-29T05:57:26-05:00",
"cancel_reason": "customer",
"total_price_usd": null,
"checkout_token": null,
"reference": null,
"user_id": null,
"location_id": null,
"source_identifier": null,
"source_url": null,
"processed_at": null,
"device_id": null,
"phone": null,
"customer_locale": "en",
"app_id": null,
"browser_ip": null,
"landing_site_ref": null,
"order_number": 1234,
"discount_codes": [],
"note_attributes": [],
"payment_gateway_names": [
"visa",
"bogus"
],
"processing_method": "",
"checkout_id": null,
"source_name": "web",
"fulfillment_status": "pending",
"tax_lines": [],
"tags": "",
"contact_email": "jon#doe.ca",
"order_status_url": "https://checkout.shopify.com/24877298/orders/123456abcd/authenticate?key=abcdefg",
"line_items": [
{
"id": 866550311766439000,
"variant_id": null,
"title": "Test Product Discount",
"quantity": 1,
"price": "99.50",
"grams": 0,
"sku": "",
"variant_title": null,
"vendor": null,
"fulfillment_service": "manual",
"product_id": 252236300325,
"requires_shipping": true,
"taxable": true,
"gift_card": false,
"name": "Test Product Discount",
"variant_inventory_management": null,
"properties": [],
"product_exists": true,
"fulfillable_quantity": 1,
"total_discount": "0.00",
"fulfillment_status": null,
"tax_lines": []
},
{
"id": 141249953214522980,
"variant_id": null,
"title": "ABSTRACT PENDANT, MULTI-COLOURED, ROSE GOLD PLATING",
"quantity": 1,
"price": "689.00",
"grams": 100,
"sku": "030711585240",
"variant_title": null,
"vendor": null,
"fulfillment_service": "manual",
"product_id": 252560506917,
"requires_shipping": true,
"taxable": true,
"gift_card": false,
"name": "ABSTRACT PENDANT, MULTI-COLOURED, ROSE GOLD PLATING",
"variant_inventory_management": null,
"properties": [],
"product_exists": true,
"fulfillable_quantity": 1,
"total_discount": "5.00",
"fulfillment_status": null,
"tax_lines": []
}
],
"shipping_lines": [
{
"id": 271878346596884000,
"title": "Generic Shipping",
"price": "10.00",
"code": null,
"source": "shopify",
"phone": null,
"requested_fulfillment_service_id": null,
"delivery_category": null,
"carrier_identifier": null,
"discounted_price": "10.00",
"tax_lines": []
}
],
"billing_address": {
"first_name": "Bob",
"address1": "123 Billing Street",
"phone": "555-555-BILL",
"city": "Billtown",
"zip": "K2P0B0",
"province": "Kentucky",
"country": "United States",
"last_name": "Biller",
"address2": null,
"company": "My Company",
"latitude": null,
"longitude": null,
"name": "Bob Biller",
"country_code": "US",
"province_code": "KY"
},
"shipping_address": {
"first_name": "Steve",
"address1": "123 Shipping Street",
"phone": "555-555-SHIP",
"city": "Shippington",
"zip": "40003",
"province": "Kentucky",
"country": "United States",
"last_name": "Shipper",
"address2": null,
"company": "Shipping Company",
"latitude": null,
"longitude": null,
"name": "Steve Shipper",
"country_code": "US",
"province_code": "KY"
},
"fulfillments": [],
"refunds": [],
"customer": {
"id": 115310627314723950,
"email": "john#test.com",
"accepts_marketing": false,
"created_at": null,
"updated_at": null,
"first_name": "John",
"last_name": "Smith",
"orders_count": 0,
"state": "disabled",
"total_spent": "0.00",
"last_order_id": null,
"note": null,
"verified_email": true,
"multipass_identifier": null,
"tax_exempt": false,
"phone": null,
"tags": "",
"last_order_name": null,
"default_address": {
"id": 715243470612851200,
"customer_id": 115310627314723950,
"first_name": null,
"last_name": null,
"company": null,
"address1": "123 Elm St.",
"address2": null,
"city": "Ottawa",
"province": "Ontario",
"country": "Canada",
"zip": "K2H7A8",
"phone": "123-123-1234",
"name": "",
"province_code": "ON",
"country_code": "CA",
"country_name": "Canada",
"default": false
}
}
}

Stock Quantity of ProductVariant not decreased in shopify shop when placing order via API

I am posting the following Order to the shopify api Order endpoint. The Order shows up in the shop and everything works as it should, except that the stock quantity of the variants in orders placed via the API are not decreased automatically by shopify. When I place an order within the admin console, they are decreased automatically. Shopify inventory tracking is turned on for the products. Any ideas would be greatly appreciated.
{
"order": {
"email": "someName#yahoo.com",
"financial_status": "paid",
"fulfillment_status": null,
"send_receipt": true,
"send_fulfillment_receipt": true,
"note": "Created by someName",
"line_items": [
{
"variant_id": 21718275463,
"quantity": 1,
"price": 99,
"requires_shipping": true,
"product_id": 6820646151
},
{
"variant_id": 21717700871,
"quantity": 1,
"price": 1000,
"requires_shipping": true,
"product_id": 6820646151
},
{
"variant_id": 21717690055,
"quantity": 1,
"price": 555,
"requires_shipping": true,
"product_id": 6821668807
}
],
"processing_method": "offsite",
"shipping_address": {
"first_name": "Chris",
"address1": "111 Love Road",
"phone": "9999999999",
"city": "St. Louis",
"zip": "63123",
"province": "MO",
"country": "United States",
"last_name": "Becker",
"name": "Chris Becker",
"country_code": "US",
"province_code": "MO"
},
"source_name": "someName",
"taxes_included": false,
"shipping_lines": [
{
"title": "standard",
"price": 0.00,
"code": null,
"source": "brand owner on shopify",
"carrier_identifier": null,
"tax_lines": null
}
],
"tags": "someName"
}
}
{
"variant": {
"id": 21718275463,
"product_id": 6820646151,
"title": "m / red",
"price": "99.00",
"sku": "",
"position": 2,
"grams": 0,
"inventory_policy": "deny",
"compare_at_price": "900.00",
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "m",
"option2": "red",
"option3": null,
"created_at": "2016-05-27T13:16:26-04:00",
"updated_at": "2016-05-28T13:28:20-04:00",
"taxable": false,
"barcode": "",
"image_id": 13217378823,
"inventory_quantity": 1,
"weight": 0,
"weight_unit": "lb",
"old_inventory_quantity": 1,
"requires_shipping": true
}
}
{
"variant": {
"id": 21717700871,
"product_id": 6820646151,
"title": "s / green",
"price": "1000.00",
"sku": "",
"position": 1,
"grams": 0,
"inventory_policy": "deny",
"compare_at_price": "1111.00",
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "s",
"option2": "green",
"option3": null,
"created_at": "2016-05-27T13:05:56-04:00",
"updated_at": "2016-05-28T12:17:22-04:00",
"taxable": true,
"barcode": "",
"image_id": 13160712135,
"inventory_quantity": 2,
"weight": 0,
"weight_unit": "lb",
"old_inventory_quantity": 2,
"requires_shipping": true
}
}
{
"variant": {
"id": 21717690055,
"product_id": 6821668807,
"title": "Default Title",
"price": "555.00",
"sku": "",
"position": 1,
"grams": 0,
"inventory_policy": "deny",
"compare_at_price": "666.00",
"fulfillment_service": "manual",
"inventory_management": "shopify",
"option1": "Default Title",
"option2": null,
"option3": null,
"created_at": "2016-05-27T13:05:39-04:00",
"updated_at": "2016-05-28T12:17:22-04:00",
"taxable": true,
"barcode": "",
"image_id": null,
"inventory_quantity": 2,
"weight": 0,
"weight_unit": "lb",
"old_inventory_quantity": 2,
"requires_shipping": true
}
}
You created a fake order using the API. Fake orders like that don't transact money or trigger the usual internal checks and balances without some extra effort. Maybe if you tried adding a fulfillment to the order, Shopify might ding inventory levels? Seems like something to try anyway.