akopdev / bitrix24-python-rest

API wrapper for working with Bitrix24 REST API over webhooks.
https://pypi.org/project/bitrix24-rest/
MIT License
63 stars 25 forks source link

Unintuitive interface when using crm.deal.productrows.set #12

Closed ipeterov closed 2 years ago

ipeterov commented 3 years ago

I went to https://training.bitrix24.com/rest_help/crm/deals/crm_deal_productrows_set.php and tried using this library like so:

bx24.callMethod(
    'crm.deal.productrows.set',
    id=order_id,
    rows=[
        {'PRODUCT_ID': 12, 'QUANTITY': 1, 'PRICE': 100}
    ],
)

This wasn't working, just removing all product rows from deal. Also response == True, so bitrix wasn't giving much useful info there.

I realised that in https://github.com/akopkesheshyan/bitrix24-python-rest/blob/master/bitrix24/bitrix24.py#L85 p was like

id=540&[rows][PRODUCT_ID]=12...

however bitrix expected

id=540&rows[PRODUCT_ID]=12...

I solved my problem by passing a dict to rows:

bx24.callMethod(
    'crm.deal.productrows.set',
    id=order_id,
    rows={
        0: {'PRODUCT_ID': 12, 'QUANTITY': 1, 'PRICE': 100}
    },
)

and got

id=540&rows[PRODUCT_ID]=12...

then my product rows were added to my deal.

Suggestion: refactor https://github.com/akopkesheshyan/bitrix24-python-rest/blob/master/bitrix24/bitrix24.py#L47-L72 to enable this workflow:

  1. visit bitrix docs
  2. copy-paste arguments from the example
  3. get a working function

It will probably break backward compatibility though.

akopdev commented 3 years ago

Well, it looks more like a bug, then feature.

Encoding should work with valid python lists, but in your case it fails.

I'll be pleased if you suggest solution that doesn't break backward compatibility.