Created
June 17, 2019 10:22
-
-
Save dinhhuydh/e7bc42768120f714c2274277591b1500 to your computer and use it in GitHub Desktop.
Create product on Bitrix24 with inbound webhook API
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
# Resolve errors: Name is not specified | |
connection = Faraday.new(url: @@base_url) | |
connection.post do |req| | |
req.url 'crm.product.add' | |
req.headers['Content-Type'] = 'application/json' | |
req.body = { fields: { NAME: product_name, PRICE: estate.gia_khoi_diem, DESCRIPTION: product_description } }.to_json | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If anyone's reading this gist while trying to build anything around a Bitrix24 Inbound Webhook and facing the "Name is not specified" error, please consider that the data MUST travel via query parameters and not the request body.
For example, if i want to add a product with the req.body that is showcased on this gist the request URL should look like:
https://<WEBHOOK_URL>/crm.product.add.json?fields[NAME]=product_name&fields[PRICE]=estate.gia_khoi_Diem&fields[DESCRIPTION]=product_description
Found out about this by analyzing the code of the official JavaScript library. More specifically the function named "prepareData" on the custom "ajax" object seen on line 1139.
Hope this helps somebody someday!