How to send in Deals using a web form?

3.4k views Asked by At

I'm trying to add a new Deal with the Pipedrive API.

To do so I've followed this tutorial: http://support.pipedrive.com/customer/portal/articles/1271064-how-to-send-in-deals-using-a-web-form

But there's something I didn't understand:

"Email API gives your company a special email address you can use to automate lead generation and adding of new contacts and organizations."

Where can I get this email address, there's no other mention of it at the tutorial?

Since I'm unable to follow the tutorial I'm trying to add a new deal with cURL, this is the code:

<?php
    $deal = array("item_type" => "deal","stage_id" => 1,"title" => "Atendimento Web Site","organization" => "Company","owner" => "[email protected]","visible_to" => 2,"person"  =>  array("name" => $nome,"email" => $email,"organization" => $empresa,"phone" => $tel));

    $deal_string = json_encode($deal);

    $ch = curl_init('https://api.pipedrive.com/v1/deals?api_token=TOKEN');
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $deal_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json, charset=UTF-8',
        'Content-Length: ' .strlen($deal_string))
    );

    echo $deal_string;
    echo curl_exec($ch);
?>

And this is what I get:

iten sent -> {"item_type":"deal","stage_id":1,"title":"Atendimento","organization":"Company","owner":"[email protected]","visible_to":2,"person":{"name":"Jo\u00e3o Neto","email":"[email protected]","organization":"Company 2","phone":"7112345678"}}
return from api -> {"success":false,"error":"Deal title must be given.","data":null,"additional_data":null}

Where's the error?

2

There are 2 answers

0
Mateus Neves On BEST ANSWER

I'd receive an email from Pipedrive Support with a full anwser.

*Hi,

Thanks for reaching out! I'm sorry to hear about the trouble!

So you're mixing up two completely separate things. You're sending in the JSON object needed for the Email API into the REST API.

You have 2 options.

  1. You could go full on with the email API. To do this you need to log into your Pipedrive account, navigate to the Settings, Features page and enable the Email API feature. Then click through to the email API page and get the email address you need to send the object to. And then alter your PHP code to send in that object to that email address as a plain text email. No curl or API token needed for that.

  2. You could clean up the data object you're sending in with the REST API. But you need to understand that the REST API works a little different from the Email API. So you can't just send in the person object along with the deal. You would first need to POST in the person with all the details to the persons endpoint and get back the ID. You can then use the person ID in the deals POST.

I hope this helps

Martin Henk | Co-Founder, Head of Customer Support Pipedrive*

1
ackuser On

About the email support it's true that you are mixing two thing, although it was also happened to me the first time. I admit it would seem strange, an API in which you can use emails.

Anyway, I was working on a simple integration between Pipedrive and another platform and I used the full REST API.

I noticed every time you have an error creating a Deal or you make a mistake in the Json (even if title is ok), you always get the same answer "error":"Deal title must be given.". Of courses it won't help you too much.

So, I recommend you to use some tools like RESTClient for Firefox to simplify the problem at the beginning or even Firebug to sniff it from https://developers.pipedrive.com/v1 making use of their tools to understand the request a little bit better. After that, you can do it more complex.

I am putting you a screenshot in which you can see the simplest example. I hope it will be useful for anyone

example of request pipedrive