2
2
25hp2019-07-08 18:42:39
Python
25hp, 2019-07-08 18:42:39

How to display certain values ​​through the AMOCRM API?

Hello. I want to display in a separate df several lines by a certain value.
The request itself: https://############.amocrm.ru/api/v2/leads?query=...
The problem is that the values ​​I need may not always be in the same place . For example:

'ID курса' : testdata['_embedded']['items'][i]['custom_fields'][3]['values'][0]['value']
# будет находится не здесь, а например в 
'ID курса' : testdata['_embedded']['items'][i]['custom_fields'][4]['values'][0]['value']

Before I understood this, I wrote the code, but as you can see, not in all cases it will produce the necessary fields (screen in red):
rows_list = []
for i in range(len(testdata['_embedded']['items'])):
    dict1 = {}
    # Так как в custom_fields нужно не менее 5 полей
    if len(testdata['_embedded']['items'][i]['custom_fields']) > 4:
        dict1.update({'ID курса' : testdata['_embedded']['items'][i]['custom_fields'][3]['values'][0]['value'],
                      'Этап сделки' : testdata['_embedded']['items'][i]['status_id'],
                      'ClientID' : testdata['_embedded']['items'][i]['custom_fields'][4]['values'][0]['value']})
        rows_list.append(dict1)
        
df1 = pd.DataFrame(rows_list) 
print(df1)

5d23645c84a6d232945604.png
From what I noted, I found that each field has a unique id, but in order to get close to it, it still turns out that the values ​​\u200b\u200bare always located in one place. (screen 2). Here he is in 3rd place, but in another transaction he may be in 4th or 5th, and so on.5d236463d1d3e345199997.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question