How to get venues based on certain categories? - api

It is supposed to be
https://api.foursquare.com/v2/venues/search?ll=40.7484,-73.9857&categoryId=4d4b7105d754a06374d81259&radius=100&limit=5&client_id=X&client_secret=X&v=20200101
4d4b7105d754a06374d81259 is the categoryId for Food.
So, I expect to get a list of venues with that category.
But I am getting venues of every kind.
Sample-
{
"meta": {
"code": 200
"requestId": "5f0d9ac6a0a468438f4f1b11"
}
"notifications": [
{
"type": "notificationTray"
"item": {
"unreadCount": 0
}
}
]
"response": {
"venues": [
{
"id": "43695300f964a5208c291fe3"
"name": "Empire State Building"
"contact": {
"phone": "+12127363100"
"formattedPhone": "+1 212-736-3100"
"twitter": "empirestatebldg"
"instagram": "empirestatebldg"
"facebook": "153817204635459"
"facebookUsername": "empirestatebuilding"
"facebookName": "Empire State Building"
}
"location": {
"address": "350 5th Ave"
"crossStreet": "btwn 33rd & 34th St"
"lat": 40.7485995507123
"lng": -73.98580648682452
"distance": 23
"postalCode": "10118"
"cc": "US"
"neighborhood": "Midtown Manhattan, New York, NY"
"city": "New York"
"state": "NY"
"country": "United States"
"formattedAddress": [
"0": "350 5th Ave (btwn 33rd & 34th St)"
"1": "New York, NY 10118"
"2": "United States"
]
}
"categories": [
"0": {
"id": "4bf58dd8d48988d130941735"
"name": "Building" # SEE HERE, ITS A BUILDING
"pluralName": "Buildings"
"shortName": "Building"
"icon": {
"prefix": "https://ss3.4sqi.net/img/categories_v2/building/default_"
"suffix": ".png"
}
"primary": true
}
]
"verified": true
"stats": {
"tipCount": 1165
"usersCount": 140228
"checkinsCount": 202739
}
"url": "https://www.esbnyc.com"
"venueRatingBlacklisted": true
"beenHere": {
"lastCheckinExpiredAt": 0
}
"venuePage": {
"id": "64514349"
}
"storeId": ""
"hereNow": {
"count": 0
"summary": "Nobody here"
"groups": [
]
}
"referralId": "v-1594727371"
"venueChains": [
]
"hasPerk": false
}
{
"id": "4bcca12bb6c49c7422169491"
"name": "86th Floor Observation Deck"
"contact": {
"phone": "+12127363100"
"formattedPhone": "+1 212-736-3100"
}
"location": {
"address": "350 5th Ave"
"crossStreet": "btwn 33rd & 34th Sts"
"lat": 40.74844544481811
"lng": -73.98568124187432
"labeledLatLngs": [
"0": {
"label": "display"
"lat": 40.74844544481811
"lng": -73.98568124187432
}
]
"distance": 5
"postalCode": "10118"
"cc": "US"
"city": "New York"
"state": "NY"
"country": "United States"
"formattedAddress": [
"0": "350 5th Ave (btwn 33rd & 34th Sts)"
"1": "New York, NY 10118"
"2": "United States"
]
}
"categories": [
"0": {
"id": "4bf58dd8d48988d165941735"
"name": "Scenic Lookout" # LOOK HERE, IT'S SCENIC LOOKOUT
"pluralName": "Scenic Lookouts"
"shortName": "Scenic Lookout"
"icon": {
"prefix": "https://ss3.4sqi.net/img/categories_v2/parks_outdoors/sceniclookout_"
"suffix": ".png"
}
"primary": true
}
]
"verified": true
"stats": {
"tipCount": 241
"usersCount": 21820
"checkinsCount": 23730
}
"beenHere": {
"lastCheckinExpiredAt": 0
}
"venuePage": {
"id": "64514350"
}
"hereNow": {
"count": 0
"summary": "Nobody here"
"groups": [
]
}
"referralId": "v-1594727371"
"venueChains": [
]
"hasPerk": false
}
{
"id": "5af44f23bcbf7a002ce0a18a"
"name": "Workday"
"contact": {
}
"location": {
"address": "350 5th Ave"
"lat": 40.748333
"lng": -73.985577
"labeledLatLngs": [
"0": {
"label": "display"
"lat": 40.748333
"lng": -73.985577
}
]
"distance": 12
"postalCode": "10001"
"cc": "US"
"city": "New York"
"state": "NY"
"country": "United States"
"formattedAddress": [
"0": "350 5th Ave"
"1": "New York, NY 10001"
"2": "United States"
]
}
"categories": [
"0": {
"id": "4bf58dd8d48988d124941735"
"name": "Office" # IT'S AN OFFICE
"pluralName": "Offices"
"shortName": "Office"
"icon": {
"prefix": "https://ss3.4sqi.net/img/categories_v2/building/default_"
"suffix": ".png"
}
"primary": true
}
]
"verified": false
"stats": {
"tipCount": 0
"usersCount": 12
"checkinsCount": 69
}
"venueRatingBlacklisted": true
"beenHere": {
"lastCheckinExpiredAt": 0
}
"hereNow": {
"count": 0
"summary": "Nobody here"
"groups": [
]
}
"referralId": "v-1594727371"
"venueChains": [
]
"hasPerk": false
}
{
"id": "5820b92252addb0cc786c053"
"name": "Expedia - New York City Office"
"contact": {
}
"location": {
"address": "350 5th Ave"
"lat": 40.748452
"lng": -73.985595
"labeledLatLngs": [
"0": {
"label": "display"
"lat": 40.748452
"lng": -73.985595
}
]
"distance": 10
"postalCode": "10118"
"cc": "US"
"city": "New York"
"state": "NY"
"country": "United States"
"formattedAddress": [
"0": "350 5th Ave"
"1": "New York, NY 10118"
"2": "United States"
]
}
"categories": [
"0": {
"id": "4bf58dd8d48988d124941735"
"name": "Office"
"pluralName": "Offices"
"shortName": "Office"
"icon": {
"prefix": "https://ss3.4sqi.net/img/categories_v2/building/default_"
"suffix": ".png"
}
"primary": true
}
]
"verified": false
"stats": {
"tipCount": 0
"usersCount": 15
"checkinsCount": 52
}
"venueRatingBlacklisted": true
"beenHere": {
"lastCheckinExpiredAt": 0
}
"hereNow": {
"count": 0
"summary": "Nobody here"
"groups": [
]
}
"referralId": "v-1594727371"
"venueChains": [
]
"hasPerk": false
}
{
"id": "59a44ba0e97dfb37208faf41"
"name": "JCDecaux, NA"
"contact": {
}
"location": {
"address": "350 Fifth Avenue, 73rd floor"
"lat": 40.74847232935598
"lng": -73.98566846513467
"labeledLatLngs": [
"0": {
"label": "display"
"lat": 40.74847232935598
"lng": -73.98566846513467
}
]
"distance": 8
"postalCode": "10001"
"cc": "US"
"city": "New York"
"state": "NY"
"country": "United States"
"formattedAddress": [
"0": "350 Fifth Avenue, 73rd floor"
"1": "New York, NY 10001"
"2": "United States"
]
}
"categories": [
"0": {
"id": "4bf58dd8d48988d124941735"
"name": "Office"
"pluralName": "Offices"
"shortName": "Office"
"icon": {
"prefix": "https://ss3.4sqi.net/img/categories_v2/building/default_"
"suffix": ".png"
}
"primary": true
}
]
"verified": false
"stats": {
"tipCount": 0
"usersCount": 21
"checkinsCount": 452
}
"venueRatingBlacklisted": true
"beenHere": {
"lastCheckinExpiredAt": 0
}
"hereNow": {
"count": 0
"summary": "Nobody here"
"groups": [
]
}
"referralId": "v-1594727371"
"venueChains": [
]
"hasPerk": false
}
]
"confident": false
}
}
So, what exactly am I doing wrong? What should be done to get only those venues in response which has their category as Food or some subcategory of it?

Your parameter is wrong. Replace categoryID with categoryId .
https://api.foursquare.com/v2/venues/search?ll=40.7484,-73.9857&categoryID=4d4b7105d754a06374d81259&radius=100&limit=5&client_id=X&client_secret=X&v=20200101 ->
https://api.foursquare.com/v2/venues/search?ll=40.7484,-73.9857&categoryId=4d4b7105d754a06374d81259&radius=100&limit=5&client_id=X&client_secret=X&v=20200101

2 things:
I read that the categoryId should come before anything else. I'm not sure if it's relevant, but it worked for me.
the radius was only 100m in your original url, I would suggest a bigger radius, as it maybe affected the result too.
For me this url worked perfectly:
https://api.foursquare.com/v2/venues/search?categoryId=4d4b7105d754a06374d81259&ll=40.7,-74&client_id=X&client_secret=X&v=20200101&radius=700&limit=20

Related

Dataweave filtering nested arrays and displaying in descending order

I'm trying to filter an array based on some values nested in objects.
My data pertains to offers (array), customers(array) with tickets(array) and other child arrays.
I want to orderBy to get all the customers information ordered by the latest timeStamp (attribute in tickets array)
From the example, offer 1 has customer 50001 with tickets 1001, 1002 and customer 50002 with tickets 1003, 1004. I want the customer which has latest timestamp in all the tickets available to be displayed first: (Desc order) with all the other passengers ordered accordingly.
Request Payload:
{
"count": 1,
"offers": [{
"offerInfo": {
"orderNumber": "1",
"orderCreationDtTime": "2023-01-10 00:00:00"
},
"customers": [{
"customerInfo": {
"name": {
"frstNm": "JOHN",
"lstNm": "DOE"
}
},
"customerNum": "50001",
"tickets": [{
"timestamp": "2023-01-07 00:38:00.167000",
"ticketService": {
"ticketNum": "1001",
"ticketType": "3"
},
"ticketReps": [{
"seq": "1",
"comment": "1st",
"location": "US"
},
{
"seq": "2",
"comment": "2nd",
"location": "US"
}
]
},
{
"timestamp": "2023-01-11 00:38:00.167000",
"ticketService": {
"ticketNum": "1002",
"ticketType": "3"
},
"ticketReps": [{
"seq": "3",
"comment": "1st",
"location": "US"
},
{
"seq": "4",
"comment": "2nd",
"location": "US"
}
]
}
]
},
{
"customerInfo": {
"name": {
"frstNm": "FAN",
"lstNm": "SING"
}
},
"customerNum": "50002",
"tickets": [{
"timestamp": "2023-01-10 00:38:00.167000",
"ticketService": {
"ticketNum": "1003",
"ticketType": "3"
},
"ticketReps": [{
"seq": "1",
"comment": "1st",
"location": "US"
},
{
"seq": "2",
"comment": "2nd",
"location": "US"
}
]
},
{
"timestamp": "2023-01-19 00:38:00.167000",
"ticketService": {
"ticketNum": "1004",
"ticketType": "3"
},
"ticketReps": [{
"seq": "1",
"comment": "1st",
"location": "US"
},
{
"seq": "2",
"comment": "2nd",
"location": "US"
}
]
}
]
}
]
}]
}
Expecting Payload after transform message:
{
"count": 1,
"offers": [{
"offerInfo": {
"orderNumber": "1",
"orderCreationDtTime": "2023-01-10 00:00:00"
},
"customers": [{
"customerInfo": {
"name": {
"frstNm": "FAN",
"lstNm": "SING"
}
},
"customerNum": "50002",
"tickets": [{
"timestamp": "2023-01-19 00:38:00.167000",
"ticketService": {
"ticketNum": "1004",
"ticketType": "3"
},
"ticketReps": [{
"seq": "1",
"comment": "1st",
"location": "US"
},
{
"seq": "2",
"comment": "2nd",
"location": "US"
}
]
},
{
"timestamp": "2023-01-10 00:38:00.167000",
"ticketService": {
"ticketNum": "1003",
"ticketType": "3"
},
"ticketReps": [{
"seq": "1",
"comment": "1st",
"location": "US"
},
{
"seq": "2",
"comment": "2nd",
"location": "US"
}
]
}
]
},
{
"customerInfo": {
"name": {
"frstNm": "JOHN",
"lstNm": "DOE"
}
},
"customerNum": "50001",
"tickets": [{
"timestamp": "2023-01-11 00:38:00.167000",
"ticketService": {
"ticketNum": "1002",
"ticketType": "3"
},
"ticketReps": [{
"seq": "3",
"comment": "1st",
"location": "US"
},
{
"seq": "4",
"comment": "2nd",
"location": "US"
}
]
},
{
"timestamp": "2023-01-07 00:38:00.167000",
"ticketService": {
"ticketNum": "1001",
"ticketType": "3"
},
"ticketReps": [{
"seq": "1",
"comment": "1st",
"location": "US"
},
{
"seq": "2",
"comment": "2nd",
"location": "US"
}
]
}
]
}
]
}]
}
Below script will help you.
%dw 2.0
output application/json
import * from dw::util::Values
---
payload update ["offers","customers"] with (
(($ map (
$ update {
case .tickets -> ($ orderBy $.timestamp as LocalDateTime {format : "yyyy-MM-dd HH:mm:ss.SSSSSS"}) [-1 to 0]
}
)) orderBy $.tickets[0].timestamp as LocalDateTime {format : "yyyy-MM-dd HH:mm:ss.SSSSSS"}) [-1 to 0]
)
A solution using the update operator for each step and auxiliary functions for clarity.
%dw 2.0
output application/json
fun convertTimestampToNumber(t)=t as LocalDateTime {format: "yyyy-MM-dd HH:mm:ss.SSSSSS"} as String {format: "yyyyMMddHHmmssSSSSSS"} as Number
fun getMaxTimestamp(t)=max(t map convertTimestampToNumber($.timestamp))
---
payload update {
case offers at .offers ->
offers map ($ update {
case customers at .customers ->
customers map ($ update {
case tickets at .tickets -> tickets orderBy ( -convertTimestampToNumber($.timestamp) )
})
orderBy ( -getMaxTimestamp($.tickets) )
}
)
}
Output:
{
"count": 1,
"offers": [
{
"offerInfo": {
"orderNumber": "1",
"orderCreationDtTime": "2023-01-10 00:00:00"
},
"customers": [
{
"customerInfo": {
"name": {
"frstNm": "FAN",
"lstNm": "SING"
}
},
"customerNum": "50002",
"tickets": [
{
"timestamp": "2023-01-19 00:38:00.167000",
"ticketService": {
"ticketNum": "1004",
"ticketType": "3"
},
"ticketReps": [
{
"seq": "1",
"comment": "1st",
"location": "US"
},
{
"seq": "2",
"comment": "2nd",
"location": "US"
}
]
},
{
"timestamp": "2023-01-10 00:38:00.167000",
"ticketService": {
"ticketNum": "1003",
"ticketType": "3"
},
"ticketReps": [
{
"seq": "1",
"comment": "1st",
"location": "US"
},
{
"seq": "2",
"comment": "2nd",
"location": "US"
}
]
}
]
},
{
"customerInfo": {
"name": {
"frstNm": "JOHN",
"lstNm": "DOE"
}
},
"customerNum": "50001",
"tickets": [
{
"timestamp": "2023-01-11 00:38:00.167000",
"ticketService": {
"ticketNum": "1002",
"ticketType": "3"
},
"ticketReps": [
{
"seq": "3",
"comment": "1st",
"location": "US"
},
{
"seq": "4",
"comment": "2nd",
"location": "US"
}
]
},
{
"timestamp": "2023-01-07 00:38:00.167000",
"ticketService": {
"ticketNum": "1001",
"ticketType": "3"
},
"ticketReps": [
{
"seq": "1",
"comment": "1st",
"location": "US"
},
{
"seq": "2",
"comment": "2nd",
"location": "US"
}
]
}
]
}
]
}
]
}

HereMap Reverse Geocode Not getting District, Street data in Iran Geo coordinates

https://revgeocode.search.hereapi.com/v1/revgeocode?at=36.080001136883894,51.43679934714218&lang=en-US&apiKey={APIKEY}&mode=retrieveAddresses&show=streetInfo
getting this response
{
"items": [
{
"title": "Iran, Iran",
"id": "here:cm:namedplace:22928285",
"resultType": "locality",
"localityType": "city",
"address": {
"label": "Iran, Iran",
"countryCode": "IRN",
"countryName": "Iran",
"county": "Iran",
"city": "Iran"
},
"position": {
"lat": 35.68877,
"lng": 51.41503
},
"distance": 0,
"mapView": {
"west": 44.03222,
"south": 25.05911,
"east": 63.333,
"north": 39.78253
}
}
]
}

Problem to fetch data in api call in flutter/dart

how can I fetch the name and team_name keys in this API data?
condition: here 18,1,17, etc are subject codes that change according to the subject and not fix this subject available in the next API call.
{
"18": {
"detail": {
"id": "18",
"name": "Hindi"
},
"list": [
{
"id": "5",
"team_name": "Gurpreet",
},
{
"id": "2",
"team_name": "Test1",
}
]
},
"17": {
"detail": {
"id": "17",
"name": "Punjabi"
},
"list": [
{
"id": "6",
"team_name": "Guru",
},
{
"id": "3",
"team_name": "Test",
}
]
},
"1": {
"detail": {
"id": "1",
"name": "History"
},
"list": [
{
"id": "7",
"team_name": "Gurpreet",
}
]
},
"19": {
"detail": {
"id": "19",
"name": "Math"
},
"list": [
{
"id": "4",
"team_name": "Gurpreet",
}
]
},
"status": true
}
Use this code. You can check keys getter to check dynamics key.
import 'dart:convert';
void main() async {
var f = {
"18": {
"detail": {"id": "18", "name": "Hindi"},
"list": [
{
"id": "5",
"team_name": "Gurpreet",
},
{
"id": "2",
"team_name": "Test1",
}
]
},
"17": {
"detail": {"id": "17", "name": "Punjabi"},
"list": [
{
"id": "6",
"team_name": "Guru",
},
{
"id": "3",
"team_name": "Test",
}
]
},
"1": {
"detail": {"id": "1", "name": "History"},
"list": [
{
"id": "7",
"team_name": "Gurpreet",
}
]
},
"19": {
"detail": {"id": "19", "name": "Math"},
"list": [
{
"id": "4",
"team_name": "Gurpreet",
}
]
},
"status": true
};
for (var o in f.keys) {
print(o);
if (f[o] is bool) {
print(f[o]);
} else { // check it is Map. I consider it always is Map
if ((f[o] as Map)['detail'] != null) {
print((f[o] as Map)['detail']['name']);
}
if ((f[o] as Map)['list'] != null) {
print((f[o] as Map)['list'][0]['team_name']); // you can use for here. please check array is not null
}
}
}
}

Bot duplicates user messages when I use DirectLine channel

I am using bot framework v4. I have developed a chatbot using .Net Core. The bot is integrated with LUIS and Qna Maker. One issue I am facing is that the bot duplicates the message that comes from the user. Please look at the screenshot below:
The replies I get from the bot are perfectly fine. The flow of the bot is as intended. I just cannot figure out why the message from user is being duplicated. I am using DirectLine for this. I will share whatever code part is needed.
{
"activities": [
{
"type": "message",
"id": "BR1wBZw7w2852JMLobk0EC-o|0000000",
"timestamp": "2019-12-02T19:41:57.1284328Z",
"channelId": "directline",
"from": {
"id": "CivicDevBot",
"name": "CivicChat"
},
"conversation": {
"id": "BR1wBZw7w2852JMLobk0EC-o"
},
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Container",
"items": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "Image",
"size": "large",
"url": "https://i.imgur.com/ViaEUnA.png"
}
]
}
],
"horizontalAlignment": "Center"
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"size": "large",
"weight": "bolder",
"color": "light",
"text": "Welcome to CIVIC Financial Services",
"wrap": true
},
{
"type": "TextBlock",
"size": "large",
"weight": "bolder",
"color": "light",
"text": "I am S.U.E",
"wrap": true
},
{
"type": "TextBlock",
"color": "light",
"text": "I can help you answer your questions. Familiarize yourself with CIVIC Financial Services.",
"wrap": true
},
{
"type": "TextBlock",
"color": "light",
"text": "If you want to talk to a Customer Service Agent, just type \"I want to talk to a Customer Service Agent\".",
"wrap": true
}
],
"separator": true,
"horizontalAlignment": "Left"
}
]
}
]
}
],
"actions": [
{
"type": "Action.Submit",
"data": {
"action": "aboutCivic"
},
"title": "About CIVIC"
},
{
"type": "Action.ShowCard",
"card": {
"type": "AdaptiveCard",
"actions": [
{
"type": "Action.ShowCard",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "We are open from Monday through Friday from 8:00am to 6:00pm.",
"wrap": true
}
],
"style": "emphasis"
},
"title": "When are you open?"
},
{
"type": "Action.ShowCard",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "Image",
"size": "stretch",
"url": "https://i.imgur.com/gBVgI25.png",
"horizontalAlignment": "center"
},
{
"type": "TextBlock",
"text": "AZ, CA, CO, FL, GA, HI, NC, NV, OR, SC, TN, TX, UT, VA & WA",
"wrap": true
}
],
"style": "emphasis"
},
"title": "Do you have an office near me? "
},
{
"type": "Action.ShowCard",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "8 to 10 days, it all depends on how it takes to get access to the property.",
"wrap": true
}
],
"style": "emphasis"
},
"title": "How quickly can we close? "
}
],
"style": "emphasis"
},
"title": "FAQs"
}
]
}
}
],
"entities": [],
"replyToId": "8WGOnspSxN3"
},
{
"type": "message",
"id": "BR1wBZw7w2852JMLobk0EC-o|0000001",
"timestamp": "2019-12-02T19:43:39.96502Z",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "r_1575315715",
"name": "",
"role": "user"
},
"conversation": {
"id": "BR1wBZw7w2852JMLobk0EC-o"
},
"textFormat": "plain",
"locale": "en-GB",
"text": "teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
"entities": [
{
"type": "ClientCapabilities",
"requiresBotState": true,
"supportsListening": true,
"supportsTts": true
}
],
"channelData": {
"siteDomain": "https://websiteae1.stackblitz.io/"
}
},
{
"type": "message",
"id": "BR1wBZw7w2852JMLobk0EC-o|0000002",
"timestamp": "2019-12-02T19:43:41.7278914Z",
"channelId": "directline",
"from": {
"id": "CivicDevBot",
"name": "CivicChat"
},
"conversation": {
"id": "BR1wBZw7w2852JMLobk0EC-o"
},
"text": "Sorry, I didn't understand. Consider rephrasing your question or contacting a customer agent",
"attachments": [],
"entities": [],
"replyToId": "BR1wBZw7w2852JMLobk0EC-o|0000001"
},
{
"type": "message",
"id": "BR1wBZw7w2852JMLobk0EC-o|0000003",
"timestamp": "2019-12-02T20:00:25.784598Z",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "r_1575315715",
"name": "",
"role": "user"
},
"conversation": {
"id": "BR1wBZw7w2852JMLobk0EC-o"
},
"textFormat": "plain",
"locale": "en-GB",
"text": "helo",
"channelData": {
"siteDomain": "https://websiteae1.stackblitz.io/"
}
},
{
"type": "message",
"id": "BR1wBZw7w2852JMLobk0EC-o|0000004",
"timestamp": "2019-12-02T20:00:26.5739342Z",
"channelId": "directline",
"from": {
"id": "CivicDevBot",
"name": "CivicChat"
},
"conversation": {
"id": "BR1wBZw7w2852JMLobk0EC-o"
},
"text": "Sorry, I didn't understand. Consider rephrasing your question or contacting a customer agent",
"attachments": [],
"entities": [],
"replyToId": "BR1wBZw7w2852JMLobk0EC-o|0000003"
},
{
"type": "message",
"id": "BR1wBZw7w2852JMLobk0EC-o|0000005",
"timestamp": "2019-12-02T20:00:27.3293896Z",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "r_1575315715",
"name": "",
"role": "user"
},
"conversation": {
"id": "BR1wBZw7w2852JMLobk0EC-o"
},
"textFormat": "plain",
"locale": "en-GB",
"text": "hello",
"channelData": {
"siteDomain": "https://websiteae1.stackblitz.io/"
}
},
{
"type": "message",
"id": "BR1wBZw7w2852JMLobk0EC-o|0000006",
"timestamp": "2019-12-02T20:00:27.6064185Z",
"channelId": "directline",
"from": {
"id": "CivicDevBot",
"name": "CivicChat"
},
"conversation": {
"id": "BR1wBZw7w2852JMLobk0EC-o"
},
"text": "Hello",
"inputHint": "acceptingInput",
"attachments": [],
"entities": [],
"replyToId": "BR1wBZw7w2852JMLobk0EC-o|0000005"
}
],
"watermark": "6"
}

How do I use the Google Civic Information API to retrieve members of Congress for a given location?

I've tried using the civicinfo.representatives.representativeInfoByAddress endpoint in the API explorer (https://developers.google.com/apis-explorer/?hl=en_US#p/civicinfo/v2/civicinfo.representatives.representativeInfoByAddress).
Here's my problem: That endpoint returns all state, federal, and local offices EXCEPT the U.S. House of Representatives! I can see the governor, senators, state senators, but NOT members of Congress. I can't find anything in the documentation to explain why this blatantly important data is being omitted, nor can I find any alternative sources (that are actually current) for this data.
Why is Google withholding the Congressional data and how do I get it? That's the ONE THING I need from this API and it seems to be missing from the results. I've tried playing with the parameters and whatnot but I can't find that data.
There has to be a way to find this information. In the Google API Explorer (see above link), try entering "WA" for the "address" field and leave everything else blank (setting the next one to TRUE makes no difference and the others are just filters). Here's the data that's returned:
{
"kind": "civicinfo#representativeInfoResponse",
"normalizedInput": {
"line1": "",
"city": "",
"state": "WA",
"zip": ""
},
"divisions": {
"ocd-division/country:us": {
"name": "United States",
"officeIndices": [
0,
1
]
},
"ocd-division/country:us/state:wa": {
"name": "Washington",
"officeIndices": [
2,
3,
4,
5,
6,
7,
8,
9,
10,
11
]
}
},
"offices": [
{
"name": "President of the United States",
"divisionId": "ocd-division/country:us",
"levels": [
"country"
],
"roles": [
"headOfState",
"headOfGovernment"
],
"officialIndices": [
0
]
},
{
"name": "Vice-President of the United States",
"divisionId": "ocd-division/country:us",
"levels": [
"country"
],
"roles": [
"deputyHeadOfGovernment"
],
"officialIndices": [
1
]
},
{
"name": "United States Senate",
"divisionId": "ocd-division/country:us/state:wa",
"levels": [
"country"
],
"roles": [
"legislatorUpperBody"
],
"officialIndices": [
2,
3
]
},
{
"name": "Governor",
"divisionId": "ocd-division/country:us/state:wa",
"levels": [
"administrativeArea1"
],
"roles": [
"headOfGovernment"
],
"officialIndices": [
4
]
},
{
"name": "Lieutenant Governor",
"divisionId": "ocd-division/country:us/state:wa",
"levels": [
"administrativeArea1"
],
"roles": [
"deputyHeadOfGovernment"
],
"officialIndices": [
5
]
},
{
"name": "State Auditor",
"divisionId": "ocd-division/country:us/state:wa",
"officialIndices": [
6
]
},
{
"name": "State Treasurer",
"divisionId": "ocd-division/country:us/state:wa",
"officialIndices": [
7
]
},
{
"name": "Attorney General",
"divisionId": "ocd-division/country:us/state:wa",
"officialIndices": [
8
]
},
{
"name": "Secretary of State",
"divisionId": "ocd-division/country:us/state:wa",
"officialIndices": [
9
]
},
{
"name": "Insurance Commissioner",
"divisionId": "ocd-division/country:us/state:wa",
"officialIndices": [
10
]
},
{
"name": "Commissioner of Public Lands",
"divisionId": "ocd-division/country:us/state:wa",
"officialIndices": [
11
]
},
{
"name": "State Superintendent of Public Instruction",
"divisionId": "ocd-division/country:us/state:wa",
"officialIndices": [
12
]
}
],
"officials": [
{
"name": "Donald J. Trump",
"address": [
{
"line1": "The White House",
"line2": "1600 Pennsylvania Avenue NW",
"city": "Washington",
"state": "DC",
"zip": "20500"
}
],
"party": "Republican",
"phones": [
"(202) 456-1111"
],
"urls": [
"http://www.whitehouse.gov/"
],
"photoUrl": "https://www.whitehouse.gov/sites/whitehouse.gov/files/images/45/PE%20Color.jpg",
"channels": [
{
"type": "GooglePlus",
"id": "+whitehouse"
},
{
"type": "Facebook",
"id": "whitehouse"
},
{
"type": "Twitter",
"id": "potus"
},
{
"type": "YouTube",
"id": "whitehouse"
}
]
},
{
"name": "Mike Pence",
"address": [
{
"line1": "The White House",
"line2": "1600 Pennsylvania Avenue NW",
"city": "Washington",
"state": "DC",
"zip": "20500"
}
],
"party": "Republican",
"phones": [
"(202) 456-1111"
],
"urls": [
"http://www.whitehouse.gov/"
],
"photoUrl": "https://www.whitehouse.gov/sites/whitehouse.gov/files/images/45/VPE%20Color.jpg",
"channels": [
{
"type": "GooglePlus",
"id": "+whitehouse"
},
{
"type": "Facebook",
"id": "whitehouse"
},
{
"type": "Twitter",
"id": "VP"
}
]
},
{
"name": "Maria Cantwell",
"address": [
{
"line1": "511 Hart Senate Office Building",
"city": "Washington",
"state": "DC",
"zip": "20510"
}
],
"party": "Democratic",
"phones": [
"(202) 224-3441"
],
"urls": [
"https://www.cantwell.senate.gov/"
],
"photoUrl": "http://bioguide.congress.gov/bioguide/photo/C/C000127.jpg",
"channels": [
{
"type": "Facebook",
"id": "senatorcantwell"
},
{
"type": "Twitter",
"id": "senatorcantwell"
},
{
"type": "YouTube",
"id": "SenatorCantwell"
}
]
},
{
"name": "Patty Murray",
"address": [
{
"line1": "154 Russell Senate Office Building",
"city": "Washington",
"state": "DC",
"zip": "20510"
}
],
"party": "Democratic",
"phones": [
"(202) 224-2621"
],
"urls": [
"http://www.murray.senate.gov/public/"
],
"photoUrl": "http://bioguide.congress.gov/bioguide/photo/M/M001111.jpg",
"channels": [
{
"type": "GooglePlus",
"id": "+pattymurray"
},
{
"type": "Twitter",
"id": "pattymurray"
},
{
"type": "YouTube",
"id": "SenatorPattyMurray"
},
{
"type": "Facebook",
"id": "pattymurray"
},
{
"type": "YouTube",
"id": "pattymurray"
}
]
},
{
"name": "Jay Inslee",
"address": [
{
"line1": "PO Box 40002",
"city": "Olympia",
"state": "WA",
"zip": "98504"
}
],
"party": "Democratic",
"phones": [
"(360) 902-4111"
],
"urls": [
"http://www.governor.wa.gov/"
],
"photoUrl": "http://www.governor.wa.gov/sites/default/files/images/720px-for-web_0.jpg",
"emails": [
"Governor.JayInslee#governor.wa.gov"
],
"channels": [
{
"type": "Facebook",
"id": "WaStateGov"
},
{
"type": "Twitter",
"id": "GovInslee"
},
{
"type": "YouTube",
"id": "UCJhWBqWVdVnPro7tx2t7j3w"
}
]
},
{
"name": "Cyrus Habib",
"address": [
{
"line1": "PO Box 40400",
"city": "Olympia",
"state": "WA",
"zip": "98504"
}
],
"party": "Democratic",
"phones": [
"(360) 786-7700"
],
"urls": [
"http://www.ltgov.wa.gov/"
],
"photoUrl": "http://www.ltgov.wa.gov/wp-content/uploads/2017/01/Senator-Habib-2015_CROPPED-225x300.jpg",
"emails": [
"ltgov#ltgov.wa.gov"
],
"channels": [
{
"type": "Twitter",
"id": "waltgov"
},
{
"type": "Facebook",
"id": "Lt-Governor-Cyrus-Habib-347384975292728"
}
]
},
{
"name": "Pat (Patrice) McCarthy",
"address": [
{
"line1": "Insurance Building Capitol Campus",
"line2": "302 Sid Snyder Avenue SW",
"city": "Olympia",
"state": "WA",
"zip": "98504"
}
],
"party": "Democratic",
"phones": [
"(360) 902-0370"
]
},
{
"name": "Duane Davidson",
"address": [
{
"line1": "PO Box 40200",
"city": "Olympia",
"state": "WA",
"zip": "98504"
}
],
"party": "Republican",
"phones": [
"(360) 902-9001"
]
},
{
"name": "Bob Ferguson",
"address": [
{
"line1": "PO Box 40100",
"city": "Olympia",
"state": "WA",
"zip": "98504"
}
],
"party": "Democratic",
"phones": [
"(360) 753-6200"
],
"urls": [
"http://www.atg.wa.gov/"
],
"channels": [
{
"type": "Facebook",
"id": "WAStateAttorneyGeneral"
},
{
"type": "Twitter",
"id": "AGOWA"
}
]
},
{
"name": "Kim Wyman",
"address": [
{
"line1": "PO Box 40220",
"city": "Olympia",
"state": "WA",
"zip": "98504"
}
],
"party": "Republican",
"phones": [
"(360) 902-4151"
],
"urls": [
"http://www.sos.wa.gov/"
],
"emails": [
"kim.wyman#sos.wa.gov"
],
"channels": [
{
"type": "Facebook",
"id": "WaSecretaryOfState"
},
{
"type": "Twitter",
"id": "secstatewa"
}
]
},
{
"name": "Mike Kreidler",
"party": "Democratic",
"phones": [
"(360) 725-7000"
],
"urls": [
"http://www.insurance.wa.gov/"
],
"channels": [
{
"type": "Facebook",
"id": "wsoic"
},
{
"type": "Twitter",
"id": "WAinsuranceblog"
}
]
},
{
"name": "Hilary Franz",
"address": [
{
"line1": "PO Box 47000",
"city": "Olympia",
"state": "WA",
"zip": "98504"
}
],
"party": "Democratic",
"phones": [
"(360) 902-1000"
]
},
{
"name": "Chris Reykdal",
"address": [
{
"line1": "Mail stop: 47200 Old Capitol Building P.O. Box 47200",
"city": "Olympia",
"state": "WA",
"zip": "98504"
}
],
"party": "Nonpartisan",
"phones": [
"(360) 725-6115"
]
}
]
}
Now, do a text search for "Adam Smith" in that JSON. He's a current member of Congress in WA. You'll notice that string is not present, nor are any other members of Congress, nor can I find any reference links in the return to look them up.
What am I missing?? It seems utterly insane to me that everything is included there except members of the U.S. House (but federal and state Senates are included). That means it's possible that the data is available somehow but I'm just not figuring it out. Can anybody help?
Thanks!
This is a couple of months late but you need to specify the to look for the roles legislatorUpperBody and legislatorLowerBody.
If you just want to have these two peices of infomation try running the query
https://www.googleapis.com/civicinfo/v2/representatives?address=[address]&levels=country&roles=legislatorUpperBody&roles=legislatorLowerBody&key=[api_key]
Instead of returning all possible results for representatives for a given area, the API seems to only return exact matches.
Assuming 2 requests that both use levels=country&roles=legislatorLowerBody.
I get 0 results using the address Boston, MA.
I get the proper representative using the address 10 Summer St, Boston, MA.
Congressional districts can be pretty specific. In some cases the street number along the same street will dictate one district versus another.