Skip to content

Instantly share code, notes, and snippets.

@BedrosovaYulia
Created April 9, 2020 07:09
Show Gist options
  • Save BedrosovaYulia/1356a7c629d833045fd062dae2f35014 to your computer and use it in GitHub Desktop.
Save BedrosovaYulia/1356a7c629d833045fd062dae2f35014 to your computer and use it in GitHub Desktop.
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