ID and labels for Field types

Hello! So I have started to use the API.

I have read another post that is similar, but the answer wasn’t clear. I just want to make sure. Also, I have not looked into webhooks. I don’t know how to use them yet, if you think they would solve my problem, I will look into them.

Before we used to export our data manually, and I wanted to automate that.

There are some differences though, between the export and the data I get via API.

Some fields have options. Every option has an ID, and a label. When getting a deal, for some fields I get the id, for other the label. It would be nice to choose, since “Stage” : “154” isn’t so clear, compared to the label of ID 154, e.g. “Contacted”.

Here are 3 examples of fields:

  • pipeline. FieldType: “double”. Shows: “id”
  • Lost Reason. FieldType: “varchar_options”. Shows: “label”
  • Any other custom field with options. FieldType: “enum”. Shows: “id”

When getting Dealfields I don’t even see the options for the Stage field. Am I missing something?
So, to make my export work right, one solution would be to have a dictionary (I am coding in Python), where associated to every id, I have the label. However, I would need a dictionary for every custom field. I could write a program that creates that dictionary, so that when I get a deal, instead of getting the ID, I will just pass it in the right dictionary and get the right label. But that would be pretty complicated. And I still wouldn’t find the stage options, so I would need to do that manually.

Am I missing something, or is this functionality not provided?

Hey Adrian,

Could you clarify a bit what you mean by “stage options”? Are you referring to different Stages of a deal? If so, these aren’t considered DealFields, but rather details of a Deal - something you would get from GET/deals/{id}

Hi David,
Thanks for your answer.

Sorry for the delay, I have been on vacation and then sick.

So very briefly, if you run an export manually via Pipedrive’s settings, you get all info pertinent to your deals for example.

If you do the same via API however, when a field contains options, you get the ID of that option instead of the label.

This makes reading the data quite difficult.

So what I did was creating a dictionary from the fields API get request, where I iterated through all the fields that have options, and had the IDs as keys and the labels as values. This way, by running the results through the right dictionary, you can display the correct label.

An example looks like this:
for row in content[‘data’]:
l = []
for field in data[0]:
if field in dealOptions:
if field == ‘Status’:
l += [dealOptions[field][row[df[field]]]]
l += [dealOptions[field][int(row[df[field]])]]
l += [’’]

First, I iterate through every deal in content[‘data’] (the response from getDeals in json).
Then I create a list (l) where I insert values for every item in the list data[0] (which is the header row of my dataset, and contains the fields). If this field is in dealOptions (the dictionary that contains the deal fields that have options), I pass the value through dealOptions (so that I get the label instead of the id).
df is another dictionary that I use to avoid writing the API keys, where the name of the field corresponds to the API key. The ‘Status’ condition I need because the keys are not integers.

This was my solution to have reproducible, and updated code.

I hope that both the problem and the solution were clear, please let me know if you have any better solutions!