Extract address from Google People JSON object in Podio - json

I am trying to extract address data from a Google People API call within Podio Workflow Automation. I am successfully extracting all other data except the address.
The situation - if I request names only, I can extract each of the separate name fields, but if I add addresses into the request, I can no longer extract the name fields, or the address fields. If I request only address, i cannot extract address fields.
For some reason including the address data seems to break the JSON..
Request for name data only and I get:
{
"resourceName": "people/c2138163302931177819",
"etag": "%EgUBAi43PRoEAQIFByIMT1hSSUpZWTVuMFk9",
"names": [
{
"metadata": {
"primary": true,
"source": {
"type": "CONTACT",
"id": "1dac48320efd215b"
}
},
"displayName": "xx xxxxx xxxxxx",
"familyName": "xxxxxx",
"givenName": "xxxxx",
"honorificPrefix": "xx",
"displayNameLastFirst": "xxxxxx, xx xxxxx",
"unstructuredName": "xx xxxxx xxxxxx"
}
]
}
Request for name and address data and I get:
{
"resourceName": "people/c2138163302931177819",
"etag": "%EggBAgwQLjc9QBoEAQIFByIMT1hSSUpZWTVuMFk9",
"names": [
{
"metadata": {
"primary": true,
"source": {
"type": "CONTACT",
"id": "1dac48320efd215b"
}
},
"displayName": "xx xxxxx xxxxxx",
"familyName": "xxxxxx",
"givenName": "xxxxx",
"honorificPrefix": "xx",
"displayNameLastFirst": "xxxxxx, xx xxxxxx",
"unstructuredName": "xx xxxxx xxxxxx"
}
],
"addresses": [
{
"metadata": {
"primary": true,
"source": {
"type": "CONTACT",
"id": "1dac48320efd215b"
}
},
"formattedValue": "xxxxxxx\nSouthampton, England xxxxxxx\nUnited Kingdom",
"streetAddress": "xxxxxxx",
"city": "Southampton",
"region": "England",
"postalCode": "xxxxxxx",
"country": "United Kingdom",
"countryCode": "GB"
}
]
}
For me this looks no different in structure, however when I've changed it to code on here it's not recognising the latter one correctly..
In Podio I am base64 encoding the response and then as an example to extract first name I use:
json_decode(base64_decode([(Variable) google_array]))->{'names'}[0]->{'givenName'}
For City I'm using
json_decode(base64_decode([(Variable) google_array]))->{'addresses'}[0]->{'city'}
Extracting the name works fine if I only request name details, but not if it includes address details as well. It is only address that seems to create this problem. I cannot extract any address details.

Sounds like your json_decode (or the encode) doesn't work well with those "\n" line breaks.
See this discussion about json_decode in PHP 7: New lines and tabs in json_decode() (PHP 7)

use str_replace to remove "\n" from JSON response before base64 encoding

Related

Convert a JSON array into a solidity mapping in a chainlink node external adapter?

I have a custom external adapter runnning on a chainlink node. When the adapter is triggered, it gets a response from an api that sends back a json object with a list of objects. I want to covert the array in this json object into a solidity mapping for my smart contract.
For example could I get the property "array of objects" from this response and convert it into a solidity mapping for my client contract to use?
"random": 89,
"random float": 10.669,
"bool": true,
"date": "1980-11-24",
"regEx": "helloooooooooooooooooooooo to you",
"enum": "json",
"firstname": "Stevana",
"lastname": "Killigrew",
"city": "Port Moresby",
"country": "Isle of Man",
"countryCode": "PY",
"email uses current data": "Stevana.Killigrew#gmail.com",
"email from expression": "Stevana.Killigrew#yopmail.com",
"array": [
"Vanessa",
"Chloris",
"Glynnis",
"Fidelia",
"Kaja"
],
"array of objects": [
{
"index": 0,
"index start at 5": 5,
"team": "na",
"company": "CVS",
"department": "hair and beauty"
},
{
"index": 1,
"index start at 5": 6,
"team": "na",
"company": "CVS",
"department": "hair and beauty"
},
{
"index": 2,
"index start at 5": 7,
"team": "na",
"company": "CVS",
"department": "hair and beauty"
}
],
"Ronna": {
"age": 82
}
}```
One can't get an "array of objects" at the moment from the external adapter, here is the list of currently supported response types.
You will need to make a Multi-Varibale Responses request and then get each individual property like this

unencode json in Zapier

I'm trying to make a Zapier zap to get a JSON from Olark.
This is the sample JSON Olark sends...
{
"kind": "Conversation",
"id": "EV695BI2930A6XMO32886MPT899443414",
"tags": ["olark", "customer"],
"items": [{
"kind": "MessageToVisitor",
"nickname": "John",
"timestamp": "1307116657.1",
"body": "Hi there. Need any help?",
"operatorId": "1234"
},
{
"kind": "MessageToOperator",
"nickname": "Bob",
"timestamp": "1307116661.25",
"body": "Yes, please help me with billing."
}],
"visitor": {
"kind": "Visitor",
"id": "9QRF9YWM5XW3ZSU7P9CGWRU89944341",
"fullName": "Bob Doe",
"emailAddress": "bob#example.com",
"phoneNumber": "(555) 555-5555",
"city": "Palo Alto",
"region": "CA",
"country": "United State",
"countryCode": "US",
"organization": "Widgets Inc.",
"ip": "123.4.56.78",
"browser": "Chrome 12.1",
"operatingSystem": "Windows",
"conversationBeginPage": "http://www.example.com/path",
"customFields": {
"myInternalCustomerId": "12341234",
"favoriteColor": "blue"
},
"chat_feedback": {
"comments": "Very helpful, thanks",
"friendliness": 5,
"knowledge": 5,
"overall_chat": 5,
"responsiveness": 5
}
},
"operators": {
"1234": {
"kind": "Operator",
"id": "1234",
"username": "jdoe",
"nickname": "John",
"emailAddress": "john#example.com"
}
},
"groups": [{
"name": "My Sales Group",
"id": "0123456789abcdef",
"kind": "Group"
}]
}
I can get what I want -- the email -- like this...
var obj = {};
var data = {};
data = JSON.parse(inputData.data);
obj.value = data.visitor["emailAddress"];
return obj;
However, the live data that comes from Olark is an encoded version of the JSON. It looks like this...
raw_body
data=%7B%22kind%22%3A+%22Conversation%22%2C+%22id%22%3A+%224pkhSGlkBYHz0gw83L6TF0UBa6rA39Bo%22%2C+%22manuallySubmitted%22%3A+false%2C+%22items%22%3A+%5B%7B%22kind%22%3A+%22MessageToOperator%22%2C+%22nickname%22%3A+%22juliachevron%40gmail.com%22%2C+%22timestamp%22%3A+%221588965389.388434%22%2C+%22body%22%3A+%22Hi.+I+have+a+stimulator+and+it+is+no+longer+working+at+the+higher+levels%22%2C+%22visitor_nickname%22%3A+%22juliachevron%40gmail.com%22%7D%2C+%7B%22kind%22%3A+%22MessageToVisitor%22%2C+%22nickname%22%3A+%22Christian%22%2C+%22operatorId%22%3A+%22663710%22%2C+%22timestamp%22%3A+%221588965397.901964%22%2C+%22body%22%3A+%22Hi+there%22%7D%2C+%7B%22kind%22%3A+%22MessageToVisitor%22%2C+%22nickname%22%3A+%22Christian%22%2C+%22operatorId%22%3A+%22663710%22%2C+%22timestamp%22%3A+%221588965408.398821%22%2C+%22body%22%3A+%22Can+you+explain+more%3F%22%7D%2C+%7B%22kind%22%3A+%22MessageToOperator%22%2C+%22nickname%22%3A+%22juliachevron%40gmail.com%22%2C+%22timestamp%22%3A+%221588965445.279921%22%2C+%22body%22%3A+%22it+is+only+flashing+up+to+the+2+and+sometimes+3%22%2C+%22visitor_nickname%22%3A+%22juliachevron%40gmail.com%22%7D%2C+%7B%22kind%22%3A+%22MessageToVisitor%22%2C+%22nickname%22%3A+%22Christian%22%2C+%22operatorId%22%3A+%22663710%22%2C+%22timestamp%22%3A+%221588965482.985280%22%2C+%22body%22%3A+%22Try+our+%5C%22oreo%5C%22+troubleshooting+test+from+page+12+of+the+User+Guide%22%7D%2C+%7B%22kind%22%3A+%22MessageToVisitor%22%2C+%22nickname%22%3A+%22Christian%22%2C+%22operatorId%22%3A+%22663710%22%2C+%22timestamp%22%3A+%221588965488.741729%22%2C+%22body%22%3A+%22It+involves+you+pressing+the+wet+sponges+into+each+other+as+you+turn+the+device+to+the+max+setting%22%7D%2C+%7B%22kind%22%3A+%22MessageToOperator%22%2C+%22nickname%22%3A+%22juliachevron%40gmail.com%22%2C+%22timestamp%22%3A+%221588965539.836595%22%2C+%22body%22%3A+%22thank+you%21%22%2C+%22visitor_nickname%22%3A+%22juliachevron%40gmail.com%22%7D%2C+%7B%22kind%22%3A+%22MessageToVisitor%22%2C+%22nickname%22%3A+%22Christian%22%2C+%22operatorId%22%3A+%22663710%22%2C+%22timestamp%22%3A+%221588965583.359044%22%2C+%22body%22%3A+%22This+test+is+to+make+sure+the+device+is+functioning+correctly%22%7D%2C+%7B%22kind%22%3A+%22MessageToVisitor%22%2C+%22nickname%22%3A+%22Christian%22%2C+%22operatorId%22%3A+%22663710%22%2C+%22timestamp%22%3A+%221588965619.075057%22%2C+%22body%22%3A+%22If+you+are+not+getting+to+the+higher+levels+when+the+sponges+are+on+your+temples%2C+it+may+mean+that+you+need+to+use+more+water%2C+tighten+the+headband+a+little+more%2C+or+that+you+need+to+replace+the+sponges%22%7D%2C+%7B%22kind%22%3A+%22MessageToOperator%22%2C+%22nickname%22%3A+%22juliachevron%40gmail.com%22%2C+%22timestamp%22%3A+%221588965698.050212%22%2C+%22body%22%3A+%22it+worked.+thanks%22%2C+%22visitor_nickname%22%3A+%22juliachevron%40gmail.com%22%7D%2C+%7B%22kind%22%3A+%22MessageToVisitor%22%2C+%22nickname%22%3A+%22Christian%22%2C+%22operatorId%22%3A+%22663710%22%2C+%22timestamp%22%3A+%221588965702.713077%22%2C+%22body%22%3A+%22You%27re+very+welcome.%22%7D%5D%2C+%22tags%22%3A+%5B%5D%2C+%22visitor%22%3A+%7B%22kind%22%3A+%22Visitor%22%2C+%22id%22%3A+%22YN7k5dd6nGH52Lvd3L6TF0VBb03B3roI%22%2C+%22fullName%22%3A+%22juliachevron%40gmail.com%22%2C+%22emailAddress%22%3A+%22juliachevron%40gmail.com%22%2C+%22ip%22%3A+%22%22%2C+%22city%22%3A+%22Oak+Park%22%2C+%22region%22%3A+%22IL%22%2C+%22country%22%3A+%22United+States%22%2C+%22countryCode%22%3A+%22US%22%2C+%22organization%22%3A+%22Comcast+Cable%22%2C+%22browser%22%3A+%22Chrome+80.0.3987.149%22%2C+%22operatingSystem%22%3A+%22Macintosh%22%2C+%22referrer%22%3A+%22https%3A%2F%2Fwww.google.com%2F%22%2C+%22conversationBeginPage%22%3A+%22https%3A%2F%2Fwww.fisherwallace.com%2F%22%2C+%22chat_feedback%22%3A+%7B%7D%7D%2C+%22operators%22%3A+%7B%22663710%22%3A+%7B%22kind%22%3A+%22Operator%22%2C+%22id%22%3A+%22663710%22%2C+%22nickname%22%3A+%22Christian%22%2C+%22emailAddress%22%3A+%22christian%40fisherwallace.com%22%2C+%22username%22%3A+%22fisherwallace%22%7D%7D%7D
And I get "SyntaxError: Unexpected token d in JSON at position 0" when I try to parse it with the code that works on the sample JSON.
Is there a way in Zapier to unencode the JSON?
There sure is! What you're seeing is percent encoding. Node.js can decode that, but to get valid json, you'll also need to replace the + characters with spaces.
Try this:
const inputWithReplacedSpaces = inputData.data.replace(/\+/g, '%20') // '%20' is a space
const jsonStr = decodeURIComponent(inputWithReplacedSpaces)
const data = JSON.parse(jsonStr)
return { email: data.visitor.emailAddress }
There were two issues. See screenshot.
I needed to set the Import Data to "data" in the Custom Run Javascript step. And also remove the "data=" from the string at the beginning of the Raw Body.

Directory users update clearing fields not included in resource

Google's documentation states that Users.update will only update fields included in the userResource object. https://developers.google.com/admin-sdk/directory/v1/reference/users/update
In my script, I am able to submit updates successfully, but when I do, fields not specified are cleared out. Here's an example:
Original user resource:
{
orgUnitPath=/,
...
"organizations": [
{
"name": "John",
"title": "developer",
"primary": true,
"department": "IT",
"location": "CA",
"description": "fulltime_employee",
"domain": "acme.com",
"costCenter": "123456"
}]
}
I want to update just one of the fields, title = 'Sr. Developer'. When I submit the partial userResource with Users.update, the rest of the fields within the array element are cleared even though they were not submitted.
Submitted userResource
{
orgUnitPath=/,
...
"organizations": [
{
"title": "sr. developer"
}]
}
Updated user
{
orgUnitPath=/,
...
"organizations": [
{
"name": "",
"title": "sr. developer",
"primary": true,
"department": "",
"location": "",
"description": "",
"domain": "",
"costCenter": ""
}]
}
Is there a way to correct this, or do I need to load each field within the element and submit them all with only the changed fields updated?

Ways to store JSON data

I'm making an API call and the response I'm getting is a rather large JSON string. I'd like to minimise API calls to a) avoid hitting the rate limit and b) speed things up.
Here's an example of my JSON data:
{
"firstName": "John",
"lastName": "Smith",
"isAlive": true,
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "office",
"number": "646 555-4567"
}
],
"children": [],
"spouse": null
}
My question:
What are my options with reference to persistent storage?
Please note: the API I'm using is in beta; so I'd like to avoid using MySQL for now because the JSON representation could change, resulting in my tables needing an overhaul.

Get all users/groups having access to a collaboration : BOX API

Is there a way to retrive all the users/groups having access to a collaboration : BOX API?
The API defines a collaboration as an access control list. It's an object that grants a single user (or group) permissions to access a folder, so you can't really have access to a collaboration.
It sounds more like you're asking how you can get a list of all the collaborations on a folder, which you can do with:
GET /folders/{id}/collaborations
which will return something like:
{
"total_count": 1,
"entries": [
{
"type": "collaboration",
"id": "14176246",
"created_by": {
"type": "user",
"id": "4276790",
"name": "David Lee",
"login": "david#box.com"
},
"created_at": "2011-11-29T12:56:35-08:00",
"modified_at": "2012-09-11T15:12:32-07:00",
"expires_at": null,
"status": "accepted",
"accessible_by": {
"type": "user",
"id": "755492",
"name": "Simon Tan",
"login": "simon#box.net"
},
"role": "editor",
"acknowledged_at": "2011-11-29T12:59:40-08:00",
"item": null
}
]
}
https://developers.box.com/docs/#folders-view-a-folders-collaborations