How to query api with filter options - rest

I am trying filter the response city wise. I am not able to understand how to query filter parameters.
I have tried different ways but with no success. This is the response without applying filter. But I want filter it for a particular city.
{
"index_name": "3b01bcb8-0b14-4abf-b6f2-c1bfd384ba69",
"title": "Real time Air Quality Index from various location",
"desc": "Real time Air Quality Index from various location",
"org_type": "Central",
"org": [
"Ministry of Environment and Forests",
"Central Pollution Control Board"
],
"sector": [
"Industrial Air Pollution"
],
"source": "data.gov.in",
"catalog_uuid": "a3e7afc6-b799-4ede-b143-8e074b27e0621",
"visualizable": "1",
"active": "1",
"created": 1543320551,
"updated": 1559683085,
"created_date": "2018-11-27T17:39:11Z",
"updated_date": "2019-06-05T02:48:05Z",
"target_bucket": {
"index": "air_quality",
"type": "a3e7afc6-b799-4ede-b143-8e074b27e0621",
"field": "3b01bcb8-0b14-4abf-b6f2-c1bfd384ba69"
},
"field": [
{
"id": "id",
"name": "id",
"type": "double"
},
{
"id": "country",
"name": "country",
"type": "keyword"
},
{
"id": "state",
"name": "state",
"type": "keyword"
},
{
"id": "city",
"name": "city",
"type": "keyword"
},
{
"id": "station",
"name": "station",
"type": "keyword"
},
{
"id": "last_update",
"name": "last_update",
"type": "date"
},
{
"id": "pollutant_id",
"name": "pollutant_id",
"type": "keyword"
},
{
"id": "pollutant_min",
"name": "pollutant_min",
"type": "double"
},
{
"id": "pollutant_max",
"name": "pollutant_max",
"type": "double"
},
{
"id": "pollutant_avg",
"name": "pollutant_avg",
"type": "double"
},
{
"id": "pollutant_unit",
"name": "pollutant_unit",
"type": "keyword"
}
],
"status": "ok",
"message": "Resource detail",
"total": 1000,
"count": 10,
"limit": "10",
"offset": "8",
"records": [
{
"id": "13",
"country": "India",
"state": "Andhra_Pradesh",
"city": "Rajamahendravaram",
"station": "Anand Kala Kshetram, Rajamahendravaram - APPCB",
"last_update": "05-06-2019 02:00:00",
"pollutant_id": "CO",
"pollutant_min": "2",
"pollutant_max": "50",
"pollutant_avg": "28",
"pollutant_unit": "NA"
},
{
"id": "14",
"country": "India",
"state": "Andhra_Pradesh",
"city": "Rajamahendravaram",
"station": "Anand Kala Kshetram, Rajamahendravaram - APPCB",
"last_update": "05-06-2019 02:00:00",
"pollutant_id": "OZONE",
"pollutant_min": "37",
"pollutant_max": "132",
"pollutant_avg": "71",
"pollutant_unit": "NA"
}
{
"id": "16",
"country": "India",
"state": "Andhra_Pradesh",
"city": "Tirupati",
"station": "Tirumala, Tirupati - APPCB",
"last_update": "05-06-2019 02:00:00",
"pollutant_id": "PM10",
"pollutant_min": "33",
"pollutant_max": "72",
"pollutant_avg": "55",
"pollutant_unit": "NA"
}
],
"version": "2.1.0"
}
This is only documentation on how to do filtering.
properties: OrderedMap { "id": OrderedMap { "type": "integer" }, "date": OrderedMap { "type": "integer" } }
How to form request url for filtering the response?

yes the documentation is very poor, but still out of many trials I got it work like
this
https://api.data.gov.in/resource/3b01bcb8-0b14-4abf-b6f2-c1bfd384ba69?api-key=<your key>&format=json&offset=0&limit=10
&filters[pollutant_id]=NO2

Related

how to test an api with array on postman

All the api used in the application have a common end point : https://m.companyname.com/application/svcwebservice.php
The json has nested arrays and the response looks like this:
[{
"usertype": [{
"id": "1",
"type": "Service Manager (Admin)",
"description": "Service Manager (Admin)"
}, {
"id": "2",
"type": "Customer Relations Executive",
"description": "Customer Relations Executive"
}, {
"id": "3",
"type": "Service Advisor",
"description": "Service Advisor"
}, {
"id": "4",
"type": "Accountant (Admin)",
"description": "Accountant (Admin)"
}, {
"id": "5",
"type": "Technician\/Mechanic",
"description": "Technician\/Mechanic"
}, {
"id": "6",
"type": "Sales Manager (Admin)",
"description": "Sales Manager (Admin)"
}, {
"id": "7",
"type": "Sales Consultant",
"description": "Sales Consultant"
}, {
"id": "8",
"type": "Receptionist",
"description": "Receptionist"
}, {
"id": "9",
"type": "Implant (Admin)",
"description": "Implant (Admin)"
}, {
"id": "10",
"type": "Vice President \/ General Manager - Sales (Admin)",
"description": "Vice President \/ General Manager - Sales (Admin)"
}, {
"id": "11",
"type": "Group Manager (Admin)",
"description": "Group Manager (Admin)"
}, {
"id": "13",
"type": "Coordinator",
"description": "Coordinator"
}, {
"id": "14",
"type": "Customer Relations Manager (Admin)",
"description": "Customer Relations Manager (Admin)"
}, {
"id": "15",
"type": "Receptionist",
"description": "Receptionist"
}, {
"id": "16",
"type": "Vice President \/ General Manager - Service (Admin)",
"description": "Vice President \/ General Manager - Service (Admin)"
}, {
"id": "17",
"type": "Principal (Admin)",
"description": "Principal (Admin)"
}, {
"id": "18",
"type": "CEO (Admin)",
"description": "CEO (Admin)"
}, {
"id": "19",
"type": "COO (Admin)",
"description": "COO (Admin)"
}, {
"id": "20",
"type": "Insurane Admin",
"description": "Insurane Admin"
}]
}]
And payload is: requesttype: "getusertypes"
The same api endpoint gives following response for another payload like:
[{
"cards": [{
"average_inv_amount": "26",
"on_time_checkin": "100.00%",
"ontime_pickup_percentage": "81.89%",
"average_distance": "5.5",
"cust_rating": "4.2",
"total_vehicle": "4"
}]
}, {
"pickup_details": [{
"name": "Awaiting",
"value": "0"
}, {
"name": "Active Pickup",
"value": "1"
}, {
"name": "Not Checked in",
"value": "0"
}, {
"name": "Checked In",
"value": "0"
}, {
"name": "Picked Up Today",
"value": "1"
}]
}, {
"drop_details": [{
"name": "Awaiting",
"value": "0"
}, {
"name": "To Service Centre",
"value": "0"
}, {
"name": "To Customer",
"value": "0"
}, {
"name": "Active Dropoff ",
"value": "0"
}, {
"name": "Delivered Today",
"value": "0"
}]
}, {
"notification": [{
"queue_paused_pickup": "0",
"queue_paused_dropoff": "0",
"not_checkedin": "1",
"queue_cancelled": "2",
"queue_rescheduled": "0",
"queue_mishaps": "0"
}]
}, {
"prepaid": [{
"pre_paid": "-250",
"credit_limit": "10000",
"show_add_credit": "1",
"allow_booking": "1"
}]
}]
and so on.
Question:
How am i supposed to test this using postman?
It depends on what you want to test.
First parse your response with
var jsonData = pm.response.json();
You can access themy by indexing like
pm.test("Your test name", function() {
var jsonData = pm.response.json();
//For Entry 4
pm.expect(jsonData[0].usertype[3].id).to.eql("4");
pm.expect(jsonData[0].usertype[3].type).to.eql("Accountant (Admin)");
pm.expect(jsonData[0].usertype[3].description).to.eql("Accountant (Admin)");
});
Or iterate over them by using for-loops. But it depends strong on your test-case.

How to check $exists in one to many relationship mongodb sails js?

Is there any way to find records that collection is empty?
For example please find below array. I want only that records with index "companydata" is empty. and also how can i get data that does not have empty "companydata" data.
Thanks in advance.
[
{
"company_id": {
"company_name": "C2",
"slug": "c2",
"is_organized": 1,
"status": "1",
"id": "5adf158f547f7f0314ca8b56",
"companydata": []
},
"user_id": "5ab889aee74a151b50d04ec1",
"status": "0",
"id": "5ae014e7432e85298081be0b"
},
{
"company_id": {
"company_name": "My Compnay",
"slug": "my-compnay",
"is_organized": 1,
"status": "1",
"id": "5ad442d98a0e0c1358ca93df",
"companydata": [
{
"name": "Bhavesh Amin",
"company_id": "5ad442d98a0e0c1358ca93df",
"status": "0",
"id": "5ad442da8a0e0c1358ca93e0"
}
]
},
"user_id": "5ab889aee74a151b50d04ec1",
"status": "0",
"id": "5ae01388432e85298081bdf8"
},
{
"company_id": {
"company_name": "Organization Name",
"slug": "organization-name",
"is_organized": 1,
"status": "1",
"id": "5ad08f9b938d1131eceea624",
"companydata": [
{
"name": "Helen H. Langley",
"company_id": "5ad08f9b938d1131eceea624",
"status": "1",
"id": "5ad08f9b938d1131eceea625"
}
]
},
"user_id": "5ab889aee74a151b50d04ec1",
"status": "0",
"id": "5ad42a5f52851a2b1449db2d"
},
]

Nested grouping of array

There are 3 master collection of category , subcategory and criteria each, i will be building framework with any possible combination of category , subcategory and criteria which will be stored as below-
framework document is added below having list of criteriaconfig as embedded object which further have single object of category , subcategory and criteria. you can refer criteriaconfig as link table that u call in mysql.
[
{
"id": "592bc3059f3ad715002b2331",
"name": "Framework1",
"description": "framework 1 for testing",
"criteriaConfigs": [
{
"id": "592bc3059f3ad715002b232f",
"category": {
"id": "591c2f5faa187956b2d0fb39",
"name": "category1",
"description": "category1",
"deleted": false,
"createdDate": 1495019359558
},
"subCategory": {
"id": "591c2f5faa187956b2d0fb83",
"name": "subCat1",
"description": "subCat1"
},
"criteria": {
"id": "591c2f5faa187956b2d0fbad",
"name": "criteria1",
"measure": "Action"
}
},
{
"id": "592bc3059f3ad715002b232e",
"category": {
"id": "591c2f5faa187956b2d0fb37",
"name": "Process",
"description": "Enagagement"
},
"subCategory": {
"id": "591c2f5faa187956b2d0fb81",
"name": "COMM / BRANDING",
"description": "COMM / BRANDING"
},
"criteria": {
"id": "591c2f5faa187956b2d0fba9",
"name": "Company representative forgets about customer on hold",
"measure": ""
}
} ]
},
{
"id": "592bc3059f3ad715002b2332",
"name": "Framework2",
"description": "framework 2 for testing",
"criteriaConfigs": [
{
"id": "592bc3059f3ad715002b232f",
"category": {
"id": "591c2f5faa187956b2d0fb39",
"name": "category1",
"description": "category1"
},
"subCategory": {
"id": "591c2f5faa187956b2d0fb83",
"name": "subCat1",
"description": "subCat1"
},
"criteria": {
"id": "591c2f5faa187956b2d0fbad",
"name": "criteria1",
"measure": "Action"
}
}
]
}
]
i need a view containing framework that will contain all list of category and inside category there will be list of added subcategory and inside subcategory will have list of criteria for single framework.
expected result -
[
{
"id": "f1",
"name": "Framework1",
"description": "framework 1 for testing",
"categories": [
{
"id": "c2",
"name": "category2",
"description": "category2",
"subCategories": [
{
"id": "sb1",
"name": "subCat1",
"description": "subCat1",
"criterias": [
{
"id": "cr1",
"name": "criteria1",
"measure": "Action"
},
{
"id": "cr2",
"name": "criteria2",
"measure": "Action"
},
{
"id": "cr3",
"name": "criteria3",
"measure": "Action"
}]
},
{
"id": "sb2",
"name": "subCat2",
"description": "subCat2",
"criterias": [
{
"id": "cr1",
"name": "criteria1",
"measure": "Action"
},
{
"id": "cr4",
"name": "criteria4",
"measure": "Action"
}]
}]
},
{
"id": "c1",
"name": "category1",
"description": "category1",
"subCategories": [
{
"id": "sb3",
"name": "subCat3",
"description": "subCat3",
"criterias": [
{
"id": "cr1",
"name": "criteria1",
"measure": "Action"
},
{
"id": "cr2",
"name": "criteria2",
"measure": "Action"
}
]},
{
"id": "sb2",
"name": "subCat2",
"description": "subCat2",
"criterias": [
{
"id": "cr1",
"name": "criteria1",
"measure": "Action"
},
{
"id": "cr4",
"name": "criteria4",
"measure": "Action"
}]
}
]
}]
},
{
"id": "f2",
"name": "Framework2",
"description": "framework 2 for testing",
"categories": [
{
"id": "c2",
"name": "category2",
"description": "category2",
"subCategories": [
{
"id": "sb4",
"name": "subCat5",
"description": "subCat5",
"criterias": [
{
"id": "cr1",
"name": "criteria1",
"measure": "Action"
},
{
"id": "cr3",
"name": "criteria3",
"measure": "Action"
}]
},
{
"id": "sb2",
"name": "subCat2",
"description": "subCat2",
"criterias": [
{
"id": "cr1",
"name": "criteria1",
"measure": "Action"
},
{
"id": "cr4",
"name": "criteria4",
"measure": "Action"
}]
}]
},
{
"id": "c1",
"name": "category1",
"description": "category1",
"subCategories": [
{
"id": "sb3",
"name": "subCat3",
"description": "subCat3",
"criterias": [
{
"id": "cr1",
"name": "criteria1",
"measure": "Action"
},
{
"id": "cr2",
"name": "criteria2",
"measure": "Action"
}
]},
{
"id": "sb2",
"name": "subCat2",
"description": "subCat2",
"criterias": [
{
"id": "cr1",
"name": "criteria1",
"measure": "Action"
},
{
"id": "cr4",
"name": "criteria4",
"measure": "Action"
}]
}
]
}]
}
]
Note - Category document doesn't have any reference to subcategory and same way subcategory doesn't have any reference to criteria object currently as they are master data and are generic , framework is created with their combination dynamically.
If you want to try to do all the work in the aggregation, you could group first by subcategory, then by category like:
db.collection.aggregate([
{$unwind:"$criteriaConfigs"},
{$project:{
_id:0,
category:"$criteriaConfigs.category",
subCategory:"$criteriaConfigs.subCategory",
criteria:"$criteriaConfigs.criteria"
}},
{$group:{
_id:{"category":"$category","subCategory":"$subCategory"},
criteria:{$addToSet:"$criteria"}
}},
{$group:{
_id:{"category":"$_id.category"},
subCategories:{$addToSet:{subCategory:"$_id.subCategory",
criteria:"$criteria"}}
}},
{$project:{
_id:0,category:"$_id.category",
subCategories:"$subCategories"
}}
])
Depending on how you plan to us the return data, it may be more efficient to return each unique combination:
db.collection.aggregate([
{$unwind:"$criteriaConfigs"},
{$group:{
_id:{
category:"$criteriaConfigs.category.name",
subCategory:"$criteriaConfigs.subCategory.name",
criteria:"$criteriaConfigs.criteria.name"
}
}},
{$project:{
_id:0,
category:"$_id.category",
subCategory:"$_id.subCategory",
criteria:"$_id.criteria"
}}
])
I'm not sure from your question what shape you are expecting the return data to have, so you may need to adjust for that.

Facebook real time updates giving incomplete information on page events

I have subscribed for page subscription for Facebook real time updates with Fields as "feed". When i am creating a new event, the Facebook real time updates sends me a wrong entry. The entry i got as a real time update is below.
{
"entry": [
{
"changes": [
{
"field": "feed",
"value": {
"photo_id": 1128416807216170,
"**post_id": "902483569809496_1128416807216170"**,
"sender_name": "Unofficial: Aerospace Demodavid",
"sender_id": 902483569809496,
"item": "photo",
"verb": "edited",
"link": "https://scontent.ford1-1.fna.fbcdn.net/t31.0-8/13717445_1128416807216170_1696828468485436508_o.jpg",
"published": 1,
"created_time": 1470269376
}
}
],
"id": "902483569809496",
"time": 1470269377
}
],
"object": "page"
}
From the above entry, if i query the Graph API for postid : 902483569809496_1128416807216170 , i get the below JSON response
{
"created_time": "2016-08-04T00:09:36+0000",
"actions": [
{
"name": "Like",
"link": "https://www.facebook.com/902483569809496/photos/gm.713007008848308/1128416807216170/?type=3"
},
{
"name": "Comment",
"link": "https://www.facebook.com/902483569809496/photos/gm.713007008848308/1128416807216170/?type=3"
},
{
"name": "See Friendship",
"link": "https://m.facebook.com/friendship/902483569809496/713006992181643/"
}
],
"from": {
"name": "Unofficial: Aerospace Demodavid",
"category": "Aerospace/Defense",
"id": "902483569809496"
},
"icon": "https://www.facebook.com/images/icons/photo.gif",
"is_hidden": false,
"is_expired": false,
"link": "https://www.facebook.com/902483569809496/photos/gm.713007008848308/1128416807216170/?type=3",
"object_id": "1128416807216170",
"picture": "https://scontent.xx.fbcdn.net/v/t1.0-0/s130x130/13892116_1128416807216170_1696828468485436508_n.jpg?oh=967e908192fcadc72eae9c11047f87e2&oe=582D6009",
"privacy": {
"allow": "",
"deny": "",
"description": "",
"friends": "",
"value": "EVERYONE"
},
"status_type": "added_photos",
"subscribed": false,
"to": {
"data": [
{
"id": "713006992181643",
"name": "Stevie G Event"
}
]
},
"type": "photo",
"updated_time": "2016-08-04T00:09:36+0000",
"id": "902483569809496_1128416807216170"
}
But the actual thing added here was an event and not a photo. The id should be 902483569809496_713006992181643 as in the below JSON and not 902483569809496_1128416807216170 which came from the real time update. Below is the JSON response which i am getting when i query the Graph API manually using the account id without using the real time update information.
{
"id": "902483569809496_713006992181643",
"from": {
"name": "Unofficial: Aerospace Demodavid",
"category": "Aerospace/Defense",
"id": "902483569809496"
},
"story": "Unofficial: Aerospace Demodavid added an event.",
"story_tags": {
"0": [
{
"id": "902483569809496",
"name": "Unofficial: Aerospace Demodavid",
"type": "page",
"offset": 0,
"length": 31
}
],
"41": [
{
"id": "713006992181643",
"name": "Stevie G Event",
"type": "event",
"offset": 41,
"length": 5
}
]
},
"picture": "https://scontent.xx.fbcdn.net/v/t1.0-0/c39.0.130.130/p130x130/13892116_1128416807216170_1696828468485436508_n.jpg?oh=5adc792bca82e0b110b3d6d98b81feae&oe=581E2680",
"link": "https://www.facebook.com/events/713006992181643/",
"name": "Stevie G Event",
"caption": "Stevie G Event",
"description": "Stevie G is the best",
"icon": "https://www.facebook.com/images/icons/event.gif",
"actions": [
{
"name": "Comment",
"link": "https://www.facebook.com/902483569809496/posts/713006992181643"
},
{
"name": "Like",
"link": "https://www.facebook.com/902483569809496/posts/713006992181643"
}
],
"privacy": {
"value": "EVERYONE",
"description": "",
"friends": "",
"allow": "",
"deny": ""
},
"type": "event",
"status_type": "created_event",
"object_id": "713006992181643",
"created_time": "2016-08-04T00:09:35+0000",
"updated_time": "2016-08-04T00:09:35+0000",
"is_hidden": false,
"is_expired": false
}
Why is there an inconsistency with the Facebook real time updates sent for an event creation. It treats it as a photo edit and not an event creation.
Please let me know if i am missing something.

what is the date format from stash api?

In the below json response, what is the date format for createdDate and updatedDate? I am not sure how to work in reverse to find what format the api is using for date. I couldn't find this any where in the documentation.
{
"size": 1,
"limit": 25,
"isLastPage": true,
"values": [
{
"id": 101,
"version": 1,
"title": "Talking Nerdy",
"description": "It’s a kludge, but put the tuple from the database in the cache.",
"state": "OPEN",
"open": true,
"closed": false,
"createdDate": 1359075920,
"updatedDate": 1359085920,
"fromRef": {
"id": "refs/heads/feature-ABC-123",
"repository": {
"slug": "my-repo",
"name": null,
"project": {
"key": "PRJ"
}
}
},
"toRef": {
"id": "refs/heads/master",
"repository": {
"slug": "my-repo",
"name": null,
"project": {
"key": "PRJ"
}
}
},
"locked": false,
"author": {
"user": {
"name": "tom",
"emailAddress": "tom#example.com",
"id": 115026,
"displayName": "Tom",
"active": true,
"slug": "tom",
"type": "NORMAL"
},
"role": "AUTHOR",
"approved": true
},
"reviewers": [
{
"user": {
"name": "jcitizen",
"emailAddress": "jane#example.com",
"id": 101,
"displayName": "Jane Citizen",
"active": true,
"slug": "jcitizen",
"type": "NORMAL"
},
"role": "REVIEWER",
"approved": true
}
],
"participants": [
{
"user": {
"name": "dick",
"emailAddress": "dick#example.com",
"id": 3083181,
"displayName": "Dick",
"active": true,
"slug": "dick",
"type": "NORMAL"
},
"role": "PARTICIPANT",
"approved": false
},
{
"user": {
"name": "harry",
"emailAddress": "harry#example.com",
"id": 99049120,
"displayName": "Harry",
"active": true,
"slug": "harry",
"type": "NORMAL"
},
"role": "PARTICIPANT",
"approved": true
}
],
"link": {
"url": "http://link/to/pullrequest",
"rel": "self"
},
"links": {
"self": [
{
"href": "http://link/to/pullrequest"
}
]
}
}
],
"start": 0
}
Just making a note that in my case, it is a UNIX timestamp, but I have to remove three trailing zeroes. E.g. the data looks like this:
"createdDate":1555621993000
If interpreted as a UNIX timestamp, that would be 09/12/51265 # 4:16am (UTC).
By removing the three trailing zeroes I get 1555621993, which is the correct time 04/18/2019 # 9:13pm (UTC)
Your mileage may vary but that was a key discovery for me :)
It looks like a UNIX timestamp.
https://en.wikipedia.org/wiki/Unix_time