There are separate web forms created on the basis of the Webform module (Drupal 7), sending by default goes to the required e-mail. Everything is within the module.

In addition, there was a need to send the data of the webform application (field) to various CRM (custom) based on JSON.

Request format

    "aCode": "zzz",
    "importdata": {
        "id": "zzz",
        "user_data": {
            "name": "zzz",
        "contact": {
            "phone": "zzz",

How do I properly implement this functionality?


External url for accepting JSON lead requests (example): http://example-server.com:8083/api/submit

After the webform has been filled in, it is necessary to automatically send the field data in the raw postdata format to the external CRM with the JSON request format specified above in the code.

  • Welcome to Drupal Answers! So far, you gave a quick description of what you want to achieve, but you didn't say what exactly you don't understand in the way to achieve it. Is there anything in particular you want to ask? Asking how to properly implement a functionality is quite broad. At least, describe what you though to do, and we can tell you what is wrong in the way you think to implement it.
    – apaderno
    Dec 19 '17 at 18:43
  • In this functionality, you should only send Webform fields to a third-party CRM in JSON format. The main question is how to make sure that the usual text fields of a particular Webform are converted to the required JSON format (specified above) and sent to the external system.
    – Alex
    Dec 20 '17 at 7:21
  • @alex you got me confused when you mentioned "Request Format" above the JSON snippet. I was of the impression that you would get a request from CRM in that format and you would respond in JSON. After you edited your question it seems that the format above is the format in which you need to send the data to the CRM. Dec 20 '17 at 14:01
  • I tried to add all the data so that it was clear what mechanism of work is needed.
    – Alex
    Dec 20 '17 at 17:29

You will need to write a custom module that will select data from the webform tables in the database, encode your response and then call the URL

$crmurl = 'http://www.crmdomain.com/api/datafromdrupal';

if (isset($response)) {
  $json_response = drupal_json_encode($response); /* Pure json encoding */

  $options = array(
             'method' => 'POST',
             'data' => $json_response,
             'timeout' => 15,
             'headers' => array('Content-Type' => 'application/x-www-form-
  $result = drupal_http_request($crmurl, $options);
  • This doesn't address the question in any way. Even if it did, the response would be invalid. You've just posted 3 very poor, incorrect answers in quick succession. Please take some time to test your solutions, and make sure you've properly understood the question, before posting.
    – Clive
    Dec 19 '17 at 14:08
  • Can you tell me why the answer doesn't address the question. Dec 19 '17 at 14:11
  • 1
    Can you tell me why it does? What's callbackurl? Where does the data from the webform come from in this answer? Why are you setting the content type header to JSON and then not sending a response containing valid JSON? Where's this $json_response var coming from and what does it contain? Why are you trying to invoke a JSON-P style mechanism when the question doesn't mention anything of the sort? Where do you put this code to make it work as the question requests? And so on
    – Clive
    Dec 19 '17 at 14:12
  • I see the echo is incorrect. Should be a drupal_http_request Dec 19 '17 at 14:19
  • See the edited comment above, that's one of several glaring errors/omissions
    – Clive
    Dec 19 '17 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.