Created
April 9, 2020 07:09
-
-
Save BedrosovaYulia/1356a7c629d833045fd062dae2f35014 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def add_b24_product(key, name, price, file_name, file_url): | |
import requests | |
import base64 | |
image_64_encode = str(base64.b64encode(requests.get(file_url).content))[2:-1] | |
product_data = { | |
"fields" : { | |
"iblockId": 1, | |
"NAME" : name, | |
"CURRENCY_ID": "RUB", | |
"PRICE" : price, | |
"PREVIEW_PICTURE": { | |
"fileData":dict() | |
} | |
} | |
} | |
product_data["fields"]["PREVIEW_PICTURE"]["fileData"]['0']=file_name | |
product_data["fields"]["PREVIEW_PICTURE"]["fileData"]['1']=image_64_encode | |
response = requests.post(key+"crm.product.add",http_build_query(product_data)) | |
result=response.json() | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment