How can I auto-populate fields with Ajax? How do I autopopulate fields in a node form in drupal 8?

Basically, what I'm trying to do is create an ajax callback to autopopulate fields based on a call to a 3rd party service.

So I'm using hook_form_alter and a custom validate function, and I'm trying to update form values.

function mymodule_validate($form, FormStateInterface &amp;$form_state) {

  $form_state-&gt;setValue('title', [['value' =&gt; 'testing 123']]);

  $form_state-&gt;setRebuild();

}


But this doesn't update the node title.

What's the correct way to alter values in a node form in an ajax callback?
I was able to get a basic autopopulation callback working based on this question:

How do I modify a core field to use Ajax and add markup?

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\ReplaceCommand;

/**
 * Implements hook_form_alter() on behalf of mymodule.module.
 */
function mymodule_form_alter(&amp;$form, FormStateInterface $form_state, $form_id) {

  if ($form_id == 'node_publication_form') {

    $form['title']['widget'][0]['value']['#value'] = 'enter title here';

    $form['import_from_third_party_service_id'] = [
      '#type' =&gt; 'textfield',
      '#title' =&gt; t('Import from third_party_service Id'),
      '#description' =&gt; t('To autopopulate fields from third_party_service, enter the third_party_service ID above in the textfield above and hit the import key below'),
      '#maxlength' =&gt; 64,
      '#size' =&gt; 8,
      '#weight' =&gt; '-10',
    ];

    $form['import_from_third_party_service_submit'] = array(
      '#name' =&gt; 'custom',
      '#type' =&gt; 'submit',
      '#value' =&gt; t('Import'),
      '#weight' =&gt; -9,
      '#ajax' =&gt; [
        'callback' =&gt; 'mymodule_import_ajax_callback',
        'wrapper' =&gt; 'import-wrapper',
      ],
    );

    $form['#prefix'] = '&lt;div id="import-wrapper"&gt;';
    $form['#suffix'] = '&lt;/div&gt;';

  }
}

function mymodule_import_ajax_callback($form, &amp;$form_state) {

  // replace with code to get value from third party service
  $new_title = 'hello world';

  $form['title']['widget'][0]['value']['#value'] = $new_title;

  return $form;
}