0

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.

Pete C
  • 21
  • 2
  • Looking at the code in here I'm wondering if it's the /n which appears in the addresses formattedValue field – Pete C Dec 21 '21 at 14:15

2 Answers2

0

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)

marmor
  • 27,641
  • 11
  • 107
  • 150
  • Thanks marmor - I’ll try and remove the \n before decoding. I don’t actually need the formattedValue information at all so I’m wondering if I can delete the field.. – Pete C Dec 23 '21 at 08:54
  • Removing the \n before base64 encode has worked a treat - thanks Marmor – Pete C Dec 23 '21 at 10:00
0

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

Pete C
  • 21
  • 2