API V2 Add Person - Unexpected Behavior

I’m facing some strange behavior trying to migrate Add Person call from v1 to v2 endpoint.

  1. In my body parameters, if I include:
{ "visible_to": 3 }

I get the error response: Validation failed: visible_to: The value ‘"3.0"’ is not a valid ‘integer’.

  1. Below find an example of my body parameters sent through:
{
  "name": "Somebody Name",
  // "visible_to": 3,
  "emails": [
	{
	  "primary": true,
	  "value": "address@email.com",
	  "label": "work"
	}
  ],
  "phones": [
	{
	  "primary": true,
	  "value": "+49155555555",
	  "label": "work"
	}
  ],
  "custom_fields": {
	"zzzb790a152749f574f1ba18abccc99674186362": "",
	"zzzeed9f473703bce7bc9190de9d873097b7d6c2": [584],
	"zzz2923bb2ff9bec88fb578ac077f96f160b5c72": [],
	"zzzf2c1f44d40ad8b19799f08b97da747b00248e": 0
  }
}

In this case I get the error response: Validation failed: emails: The value is not a valid ‘array’.; custom_fields: The value is not a valid ‘array’.; phones: The value is not a valid ‘array’.
I’m not sure if I’m formatting something wrong or if the endpoint has some issue?

Hey,

I did a quick test myself and everything seems to be working as expected. Here are the curls of the endpoints I tested:

curl --location 'https://app.pipedrive.com/api/v2/persons?api_token=TOKEN_HERE' \
--header 'Content-Type: application/json' \
--data '{ 
    "name": "Somebody Name", 
    "visible_to": 3
}'
curl --location 'https://app.pipedrive.com/api/v2/persons?api_token=API_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{
  "name": "Somebody Name",
  "visible_to": 3,
  "emails": [
	{
	  "primary": true,
	  "value": "address@email.com",
	  "label": "work"
	}
  ],
  "phones": [
	{
	  "primary": true,
	  "value": "+49155555555",
	  "label": "work"
	}
  ]
}'

I think in your first case whichever language/library you are using is treating the ‘3’ in your code as a double instead of an integer and actually passes it as ‘3.0’, which fails the API validation on Pipedrive side.

In the second example, the format of everything seems to be correct. I think you might be getting the validation errors because of some odd behavior with the commented out line in the JSON as JSON does not natively support comments, although I was unable to reproduce such an error. You could try removing the commented out line and seeing if it works then.

1 Like

Hi, thank you for responding. I had a few issues going on here (should have shared my entire setup and not the trimmed version as above).

I’m using Google Scripts to make the API calls to Pipedrive. For v1 calls, I had:

"accept": "application/json",
"contentType": "application/x-www-form-urlencoded",

For v2 calls I need instead:

"accept": "application/json",
"contentType": "application/json",

The other issues went away when I removed keys with empty values from the payload, ie change from this:

  "custom_fields": {
	"zzzb790a152749f574f1ba18abccc99674186362": "",
	"zzzeed9f473703bce7bc9190de9d873097b7d6c2": [584],
	"zzz2923bb2ff9bec88fb578ac077f96f160b5c72": [],
	"zzzf2c1f44d40ad8b19799f08b97da747b00248e": 0,
	"zzz02b1cfd7f1cbc878ec058ce7b121892c28a54": null
  }

to this:

  "custom_fields": {
	"zzzeed9f473703bce7bc9190de9d873097b7d6c2": [584],
	"zzzf2c1f44d40ad8b19799f08b97da747b00248e": 0
  }

and also need to JSON.stringify(thePayload) before sending with this updated format.