Multiple phone numbers to a contact person already in Pipedrive

I’m trying to add multiple phone numbers to a person already in Pipedrive using the api. The docs say that phone is an array, but I can’t figure out how to add more than one.

https://developers.pipedrive.com/docs/api/v1/#!/Persons/put_persons_id
If you go to the link above, and type multiple phone numbers in, only one phone number is added’

Phone numbers (one or more) associated with the person, presented in the same manner as received by GET request of a person.
https://developers.pipedrive.com/docs/api/v1/#!/PersonFields/get_personFields_id

1 Like

I’m trying to do the same thing, but I’m not a developer like you guys, I’m using Zapier. Is there a way to write multiple phone numbers to a person through Zapier? Thanks!

Yep, just did it. You’ll have to do:

^^ For the JSON array as string variable to be used in your webhook, you’ll need:

  • A previous JS step with a JSON array object as follows:
  • {“phone”:[{“primary”:“True”,“value”:"+10004447777",“label”:“work”},{“primary”:“False”,“value”:"+10003335555",“label”:“home”}],“pipedriveFieldIdString1”:“fieldValue1”,“pipedriveFieldIdString2”:“fieldValue2”}
  • Note only the 1st “phone” array item can have a “primary” value of “True”, the rest should be “False”
  • “pipedriveFieldIdString1/2”: used if there are additional Pipedrive Person fields you’d like to update in the same request
  • When array object is fully populated, create a new string var = JSON.stringify(yourJSONarrayObject);
  • This string var is what you will pass to Data in the Webhook step mentioned above

If you’re having trouble getting the client’s previous phone details (multiple phone #s as array, phone.primary and phone.label in addition to phone.value), you need to fire a Webhook GET to [ https://yourcompany.pipedrive.com/v1/persons/{{63896334__id}}?api_token=yourapitokenstring ] with header [ Accept = application/json ].

And finally below is working JS code to take existing phone numbers from Pipedrive [inputData.phoneExistsPrimary , inputData.phoneExistsValue , inputData.phoneExistsLabel from the Webhook GET just described] plus a new phone number for the same client [inputData.phoneLocal provided by you] – and currently pushes the “new” phone number to the front/top of the list in Pipedrive (change using var in 1st line). The var strFinal is what will be used for Data in the Webhook PUT to update client details.

JS Code:

var newPhoneLabel = "work"; // if you want to use a different Label for the "new" phone number in Pipedrive
var optionsFrontBack = "front"; // currently set to "front" (Primary in Pipedrive) -- change this to anything but "front" to add to the back/bottom of the Pipedrive list instead
var phoneFinal = [];
if(inputData.phoneExistsValue) {
  var splitValues = inputData.phoneExistsValue.split(',');
  var splitPrimary = inputData.phoneExistsPrimary.split(',');
  var splitLabels = inputData.phoneExistsLabel.split(',');
  for(var i=0;i<splitValues.length;i++) {
      var pushExists = {};
      pushExists["primary"] = splitPrimary[i];
      pushExists["value"] = splitValues[i];
      pushExists["label"] = splitLabels[i];
      phoneFinal.push(pushExists);
  }
  if(inputData.phoneLocal) {
    var phoneMatched = 'n';
    for(var i=0;i<phoneFinal.length;i++) {
      phoneMatched = phoneFinal[i].value==inputData.phoneLocal ? 'y' : phoneMatched;
    }
    if(phoneMatched=='n') {
		if(optionsFrontBack=="front") {
		  phoneFinal.reverse();
		  var pushLocal = {};
		  pushLocal["primary"] = "True";
		  pushLocal["value"] = inputData.phoneLocal;
		  pushLocal["label"] = newPhoneLabel;
		  phoneFinal.push(pushLocal);
		  phoneFinal.reverse();
		  for(var j=1;j<phoneFinal.length;j++) {
		    phoneFinal[j]["primary"] = "False";
		  }
		} else {
		  var pushLocal = {};
		  pushLocal["primary"] = "False";
		  pushLocal["value"] = inputData.phoneLocal;
		  pushLocal["label"] = newPhoneLabel;
		  phoneFinal.push(pushLocal);
		}
    }
  }
} else {
  if(inputData.phoneLocal) {
      var pushLocal = {};
      pushLocal["primary"] = "True";
      pushLocal["value"] = inputData.phoneLocal;
      pushLocal["label"] = newPhoneLabel;
      phoneFinal.push(pushLocal);
  }
}
var arrFinal = {};
if(phoneFinal.length>0) { arrFinal["phone"] = phoneFinal; }
// 2 lines below... if there are additional Pipedrive Person fields you'd like to update in the same request
if("fieldValue1"!=="") { arrFinal["pipedriveFieldIdString1"] = "fieldValue1"; }
if("fieldValue2"!=="") { arrFinal["pipedriveFieldIdString2"] = "fieldValue2"; }
var strFinal = JSON.stringify(arrFinal);
output = [{strFinal: strFinal}];
2 Likes

@paulieweb that works great! Thank you so much!

1 Like