Using webhook to trigger API get request

  • 0
  • 1
  • Question
  • Updated 4 months ago
  • Answered
Quickbase uses stupid mapbox - It is currently not supporting our country, so I have a workaround in terms of getting addresses sorted:  www.what3words.com

All our customers will have a unique 3 word address that is simply copied and pasted into a single field, I then want to trigger an API request to get the 3 word address translated into GPS co ordinates and entered into "Street 1, Street 2" of the Location type field.

Its pretty simple logic, but I just need help to get the format for the webhook and how to get the info into my table.

The API get request documentation: (https://docs.what3words.com/api/v2/#forward)

Here is the format of the request:

https://api.what3words.com/v2/forward?addr=[myfieldhere]&display=full&format=xml&key=[myapikeyhere]


So in the URL, I can easily use the required markers, however I don't know how to receive the payload back into a field in my record on Quickbase.

Any help here would be appreciated.  On or off world.
Photo of Geoffrey

Geoffrey

  • 1,730 Points 1k badge 2x thumb

Posted 4 months ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 26,352 Points 20k badge 2x thumb
This is trivial to do although I would suggest you don't use a webhook - just use script from your form. There is no point in making it more complicated by implementing it through a webhook.

Here is the code that takes QuickBase HQ's (150 Cambridgepark Dr, Cambridge, MA 02140) three word identifier (puns.chew.snow) and gets the JSON response and in particular the lat, lon and map url:
var apikey = "YOUR API KEY";
var addr = "puns.chew.snow";
var url = `https://api.what3words.com/v2/forward?addr=${addr}&display=full&format=json&key=${apikey...;
$.get(url)
  .then(function(json) {
    console.log(json.geometry.lat);
    console.log(json.geometry.lng);
    console.log(json.map);
    console.log(JSON.stringify(json, null, "  "));
  });

Here is the console output:
42.394445
-71.146089
http://w3w.co/puns.chew.snow
{
  "thanks": "Thanks from all of us at index.home.raft for using a what3words API",
  "crs": {
    "type": "link",
    "properties": {
      "href": "http://spatialreference.org/ref/epsg/4326/ogcwkt/";,
      "type": "ogcwkt"
    }
  },
  "words": "puns.chew.snow",
  "bounds": {
    "southwest": {
      "lng": -71.146107,
      "lat": 42.394432
    },
    "northeast": {
      "lng": -71.146071,
      "lat": 42.394459
    }
  },
  "geometry": {
    "lng": -71.146089,
    "lat": 42.394445
  },
  "language": "en",
  "map": "http://w3w.co/puns.chew.snow";,
  "status": {
    "reason": "OK",
    "status": 200
  }
}

And if you don't want to use jQuery here is the equivalent code using the Fetch API:

fetch(url)
  .then(res => res.json())
  .then((json) => {
    console.log(json.geometry.lat);
    console.log(json.geometry.lng);
    console.log(json.map);
    console.log(JSON.stringify(json, null, "  "));
  });
You can test this code from the console and then implement it using the IOL technique. Instead of logging the lat/lon you would just fill in a form value using code similar to this:
_fid_7.value = json.geometry.lat;
_fid_8.value = json.geometry.lng;
_fid_9.value = json.map;
(Edited)
Photo of Geoffrey

Geoffrey

  • 1,730 Points 1k badge 2x thumb
Thanks for this Dan.  I'll give it a bash and see how it comes out.