The idea got nixed at work, so i had to port it over to my personal testing area. Since I wasn’t under any deadline pressure, I was able to break it down into smaller pieces.
First, I just focused on getting the values from a tv and formatting/playing around with them. Code:
if ($mode == 'new') return;
if ($resource->get('template') != 6) return;
$originalValue = $resource->getTVValue('original-tv');
if (empty($originalValue) || gettype($originalValue) != 'string') return;
$formattedValue = strtoupper($originalValue);
if (!$resource->setTVValue('formatted-tv', $formattedValue)) {
$modx->log(xPDO::LOG_LEVEL_ERROR, 'formatted value could not be set');
}
return;
I’m sure there is some smarter php way to write some of this stuff. I’m coming from a JS heavy (functional) background. With that covered, I moved into just making the request itself and getting that to show up in the console, using print_r($var)
like mark said.
So I made a new plugin and added on my required fetch (rest) code. Code:
$rest_client = $modx->getService('rest', 'rest.modRest');
$response = $rest_client->get($request);
$response_array = $response->process();
if (empty($response_array)) return;
$results = $response_array['results'];
Then I’m able to just loop through the response and find the most confident result, and add that information to the required TVs. Code:
foreach($results as $item) {
$confidence = $item['confidence'];
if ($confidence < 6) continue;
$lat = $item['geometry']['lat'];
$lng = $item['geometry']['lng'];
$formatted_address = $item['formatted'];
$coordinates = array(
'lat' => $lat,
'lng' => $lng
);
break;
}
if (!empty($formatted_address)) {
$resource->setTVValue('address', $formatted_address);
}
if (!empty($coordinates['lat']) && !empty($coordinates['lng'])) {
$resource->setTVValue('lat', $coordinates['lat']);
$resource->setTVValue('lng', $coordinates['lng']);
}
So, I achieved what I came out here to do. But since I’ve personally used posts 8+ years old from the previous forums, is there anything that can be done differently/any red flags? Don’t wanna lead anyone a stray 
All the code put together, including logging messages
<?php
$event_name = $modx->event->name;
if ($event_name !== 'OnDocFormSave') return;
if ($resource->get('template') !== 6) return;
$address = $resource->getTVValue('address');
if (empty($address)) return;
$GEOCODE_URL='https://api.opencagedata.com/geocode/v1/json?q=';
$GEOCODE_PARAMS='&no_annotations=1&countrycode=us';
$address_encoded = urlencode($address);
$request = $GEOCODE_URL . $address_encoded . $GEOCODE_PARAMS;
$modx->log(xPDO::LOG_LEVEL_ERROR, 'Loading rest class');
$rest_client = $modx->getService('rest', 'rest.modRest');
$response = $rest_client->get($request);
$response_info = $response->responseInfo;
$response_error = $response->responseError;
$response_array = $response->process();
if (!empty($response_info)) {
$modx->log(xPDO::LOG_LEVEL_ERROR, 'response info');
$modx->log(xPDO::LOG_LEVEL_ERROR, print_r($response_info));
}
if (!empty($response_error)) {
$modx->log(xPDO::LOG_LEVEL_ERROR, 'response error');
$modx->log(xPDO::LOG_LEVEL_ERROR, print_r($response_error));
}
if (empty($response_array)) return;
$modx->log(xPDO::LOG_LEVEL_ERROR, 'response array');
$modx->log(xPDO::LOG_LEVEL_ERROR, print_r($response_array['results']));
$results = $response_array['results'];
foreach($results as $item) {
$confidence = $item['confidence'];
if ($confidence < 6) continue;
$lat = $item['geometry']['lat'];
$lng = $item['geometry']['lng'];
$formatted_address = $item['formatted'];
$coordinates = array(
'lat' => $lat,
'lng' => $lng
);
break;
}
if (!empty($formatted_address)) {
$resource->setTVValue('address', $formatted_address);
}
if (!empty($coordinates['lat']) && !empty($coordinates['lng'])) {
$resource->setTVValue('lat', $coordinates['lat']);
$resource->setTVValue('lng', $coordinates['lng']);
}
return;