SOLVED

Scripting & Reverse Geocoding Question

Go to solution
chriszeng
Level 1

Scripting & Reverse Geocoding Question

Hi there, 

 

We are receiving data in a string field that includes longitude and latitude information similar to the example below. As I'm new to scripting, I'm looking to understand how would I be able to pull out the x and y data to separate fields.

 

Additionally, the next step after would be to create a webhook with the Google Maps Geocoding API (or Reverse Geocoding) to spit out the Country of these coordinates: https://developers.marketo.com/webhooks/examples/

 

Field Name: Lead Data

Field Value:

{"company":"TEST" ,"description":"TEST DESCRIPTION" ,"x":-83.223971,"y":44.9009925,"Industry_Name":"Electronics","experiments":[]}

 

If anyone has advice on either the scripting or the geocoding webhook portion, I'd greatly appreciate it!

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Scripting & Reverse Geocoding Question

Like Jay says, you must parse that JSON to extract the lat/lng before sending it to Google.

 

But you're in luck: because that value is a full valid JSON string, you don't need a custom service to parse it.

 

(Note for the future: it's never a good idea to store JSON unless you know what you're doing with it.)

 

Because it's a JSON string, you can pass it to a free echo service to get the individual fields. Postman Echo is such a service.

SanfordWhiteman_0-1622123918210.png

Note the Request Token Encoding is None, not JSON.

 

You must set a Custom Header because of this non-traditional setup:

SanfordWhiteman_2-1622124457447.png

 

Then you can use Response Mappings.

SanfordWhiteman_4-1622124658445.png

 

Now, you have the individual fields and can send them to Maps in a separate webhook.

 

 

 

 

 

View solution in original post

2 REPLIES 2
Jay_Jiang
Level 10

Re: Scripting & Reverse Geocoding Question

Firstly, I'm not sure what kind of scripting you're referring to. But since you mentioned webhooks, if you don't mind using your own server to host a handler script, you can send the full json payload to your script which can then:

1. parse the json

2. extract the x and y co-ordinates

3. send the x and y co-ordinates to the google maps service and receive the response

4. handle the response as needed for marketo to writeback value/s

 

Use your favourite language to write your handler script, php is an easy start!

SanfordWhiteman
Level 10 - Community Moderator

Re: Scripting & Reverse Geocoding Question

Like Jay says, you must parse that JSON to extract the lat/lng before sending it to Google.

 

But you're in luck: because that value is a full valid JSON string, you don't need a custom service to parse it.

 

(Note for the future: it's never a good idea to store JSON unless you know what you're doing with it.)

 

Because it's a JSON string, you can pass it to a free echo service to get the individual fields. Postman Echo is such a service.

SanfordWhiteman_0-1622123918210.png

Note the Request Token Encoding is None, not JSON.

 

You must set a Custom Header because of this non-traditional setup:

SanfordWhiteman_2-1622124457447.png

 

Then you can use Response Mappings.

SanfordWhiteman_4-1622124658445.png

 

Now, you have the individual fields and can send them to Maps in a separate webhook.

 

 

 

 

 

View solution in original post