I'm new to Ruby and trying to use the Ruby gem 'rest-client' to access the REST API of my accounting system, e-conomic.com. I am able to connect via tokens and e.g. fetch customer details - so far, so good.
However, I'm struggling to figure out how to POST and thus create a new customer entry with e.g. address, name, mail etc.. In particular, I'm looking to get the code to both include my authentication token details (i.e. content of hHeader below), while also including a payload of customer details.
Details about the customer creation via the REST API: https://restdocs.e-conomic.com/#post-customer-groups
Details about the rest-client ruby gem: https://github.com/rest-client/rest-client
I'm running Ruby 2.3.3 on Windows 7 in the Atom editor. My code is as below:
Dir.chdir 'C:\Ruby23\bin'
require 'rest-client'
require 'rconomic'
require 'json'
hHeader = {"X-AppSecretToken" => 'tokenID1_sanitized', "X-AgreementGrantToken" => 'tokenID2_sanitized', "Content-Type" => 'application/json'}
hCustomer = RestClient.get("https://restapi.e-conomic.com/customers/5", hHeader) # => creates a response showing customer 5 (shown for example of GET)
Your input would be much appreciated!
Martin
You put the wrong api doc, it's POST customer, not POST customer-groups. You should send the post with:
body = {'address' => 'Example Street', 'name' => 'John Doe'}.to_json
RestClient.post "https://restapi.e-conomic.com/customers/", body, hHeader)