siddiq
siddiq

Reputation: 1711

Drupal 8 - Submit Webform to an external API

I have a Webform on my Drupal website(8.8.5). The Webform has multiple fields along with two file fields.

When the user submits the Webform, I want to send the details to an external API (SugarCRM) including the files attached in the Webform.

How can I do this? Is there a module available in Drupal 8 to achieve this easily? Or do I need to handle the data submitted and call the API manually?

I also would like to store the data on the website as it works usually.

Upvotes: 0

Views: 2029

Answers (1)

baikho
baikho

Reputation: 5368

I believe Webform SugarCRM Integration may be just what you are after. It has a stable release 8.x-2.1 for Drupal 8.

If it doesn't suit your needs, you could write your own custom Webform handler. Something like the below, extending Webform's WebformHandlerBase class:

<?php

namespace Drupal\your_module\Plugin\WebformHandler;

use Drupal\webform\Plugin\WebformHandlerBase;

/**
 * Class SugarCrmWebformHandler.
 *
 * @package Drupal\your_module\Plugin\WebformHandler
 *
 * @WebformHandler(
 *   id = "sugar_crm",
 *   label = @Translation("Sugar CRM"),
 *   category = @Translation("External"),
 *   description = @Translation("Webform handler integrating with Sugar CRM."),
 *   cardinality = \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_SINGLE,
 *   results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED,
 * )
 */
class SugarCrmWebformHandler extends WebformHandlerBase {

  /**
   * {@inheritdoc}
   */
  public function postSave(WebformSubmissionInterface $webform_submission, $update = TRUE) {
    # code for Sugar CRM...
  }

}

Alternatively you could also look into using Webform's RemotePostWebformHandler class which may provide some boilerplate for your integration.

See additional resources:

Upvotes: 1

Related Questions