The main problem is that when updating a list item, we need to fill not only field we need to update but all the fields.
Therefore, before the update, we must first request all the fields of the element by ID, reformat them into another array, and only then update.
http_build_query function: https://gist.github.com/BedrosovaYulia/2373bf43b4f89ee4479cc04ab1d0ceff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from botocore.vendored import requests | |
def lambda_handler(event, context): | |
ib_id=event['ib_id'] | |
el_id=event['id'] | |
data={ | |
'IBLOCK_TYPE_ID': 'lists', | |
'IBLOCK_ID': ib_id, | |
'ELEMENT_ID': el_id, | |
} | |
response = requests.get('https://bedrosova.bitrix24.ru/rest/1/****************/lists.element.get',data) | |
list_data=response.json() | |
fields={ | |
"NAME":list_data['result'][0]['NAME'] | |
} | |
for k in list_data['result'][0]: | |
if(k.startswith('PROPERTY')): | |
for k2 in list_data['result'][0][k]: | |
fields[k]=list_data['result'][0][k][k2] | |
fields['PROPERTY_447']='222' | |
data={ | |
'IBLOCK_TYPE_ID': 'lists', | |
'IBLOCK_ID': ib_id, | |
'ELEMENT_ID': el_id, | |
'FIELDS':fields | |
} | |
response = requests.get('https://bedrosova.bitrix24.ru/rest/1/************/lists.element.update',http_build_query(data)) | |
result=response.json() | |
#print(result) | |
return { | |
'statusCode': 200, | |
'body': json.dumps('Hello from Lambda!') | |
} |
Comments
Post a Comment