Google Scripts in a deal vs Pipedrive

How can I get a data in google scripts of a deal? For example: data.title
What am I doing wrong in my code
Thnx in advance.

var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(“Pipe”);
var url = “https://api.pipedrive.com/v1/deals/8350?api_token=xxxxxxxxxxx”;
var response = UrlFetchApp.fetch(url);
var dataSet = JSON.parse(response.getContentText());
var data;
data = dataSet.data[0];
Browser.msgBox(data.title);

Since you’re requesting a specific deal, there’s no need to get the first element with data[0].
You should probably simply do

data = dataSet.data;

Can you try that and see if it works? :slight_smile:

1 Like

Yes, its work!. Thanks god dani!

1 Like

No worries. Glad it helped :slight_smile:

Perfect with dataSet.data

But i have my Json with
{“success”:true,“data”:{“title”:“Test Titlel”,“200a8f1bbf06942f7270c24bc35ff235ade3e”:“2018-03-12”},“additional_data”:…

with data.title i parse de titlte, perfect.

but how can i parse that 200a8f1bbf06942f7270c24bc35ff235ade3e, i need that “date”

Thanks in advance.

That one looks like a custom field.

You need to make another call to https://your-company.pipedrive.com/v1/dealFields?api_token=xxxxxxxxxxx (or /personFields, /activityFields, etc.) to get the list of fields, and then match the key to get the name of the field.

Let me know if that helps.

Thanks Daniel, you are a genius!
I make a match in / personField, it gives me the correct field, but I would also need “the date” that it gives me as an answer
https://api.pipedrive.com/v1/deals/5555?api_token=xxxxxxxxxxxxxx
{“Success”: true, “data”: {“title”: “Test Titlel”, “200a8f1bbf06942f7270c24bc35ff235ade3e”: “2018-03-12”}, “additional_data”: …

Do you mean this?

data['200a8f1bbf06942f7270c24bc35ff235ade3e']

Genius! I needed that.
Thank you, thank you very much!!!.

1 Like

Nice! :smile:
You’re super welcome.

Hi there :wave:

You can simply add an option parameter to the UrlFetchApp.fetch method, like this.

var url = 'https://api.pipedrive.com/v1/deals/?api_token=xxxxx';
var data = {
    "title": "New Deal"
};
var options = {
    "method": "post",
    'contentType': 'application/json',
    "payload": JSON.stringify(data)
};
var response = UrlFetchApp.fetch(url, options);

You can find all the details on the Google Script documentation (that’s how I figured it out as well).
here: https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app#fetch(String,Object)

Dani, thans, your code its ok
But i need, “upload a file of google drive, to a DEAL, with Json”.
Can you help me?
Thanks in advance.

Then it’s probably slightly different from simply adding a deal. I would suggest looking into Google Script’s documentation.
Here are the links you need to read…

Pipedrive’s API reference for adding files: https://developers.pipedrive.com/docs/api/v1/#!/Files/post_files
Google Script documentation: https://developers.google.com/apps-script/reference/

:metal:

Thanks Dani i see that links.

Hi Dani,

I’m trying to build a logic where based on “To” param from my cloud telephony, I’ll create a deal dynamically for a specific. Created array as well in row 3 but getting truncated server response:

var ID = "1xtkrT0LTnSqxuU8rrxxxx"
var SHEET_NAME = "Miss call Assignment"
var UserID = { "08046810620": "4421772", "08046810617": "5070776", "08046810618": "6272609", "08046810620": "5839454", "08046810616": "5709457", "08047104949": "8496220", "8046810616": "5709457" }

function doGet(e) {
    var params = JSON.stringify(e.parameters);
    var jsonMapping = JSON.parse(params)
    var sheet = SpreadsheetApp.openById(ID).getSheetByName(SHEET_NAME)
    sheet.appendRow([jsonMapping["From"][0], jsonMapping["To"][0], jsonMapping["CurrentTime"][0]])
    var Customernum = jsonMapping["From"][0];
    var timePeriod = jsonMapping["CurrentTime"][0];
    var agentnum = jsonMapping["To"][0];
    CreatePipedriveDeals(UserID);
    return ContentService.createTextOutput(e.parameters)
}

function CreatePipedriveDeals(UserID) {
    var url = 'https://api.pipedrive.com/v1/deals/?api_token=dbdjsbdxxxxxx';
    var formData = {
        'user_id': "" + UserID,
    };
    var data = {
        "title": "New Deal test anuj 1",
        "user_id": "formData",
        "stage_id": "259",
        "status": "open"
    };

    var options = {
        "method": "post",
        'contentType': 'application/json',
        "payload": formData
    };
    var response = UrlFetchApp.fetch(url, options);
}