Open cabezud opened 9 years ago
Hi @cabezud I don't think just {"OPPORTUNITY_NAME"=>"Test123"}
will be enough to create a valid opportunity. Have a look at the Insightly docs for opportunity creation.
https://api.insight.ly/v2.1/Help/Api/POST-Opportunities
Their advice makes sense and it's as follows.
A common source of problems when creating opportunities occurs when users omit required fields, or insert invalid data into a field (for example by referencing an invalid CATEGORY_ID). A good troubleshooting technique is to create a few opportunities via the web interface, with representative data, links, etc, and then access these opportunities via the API, and inspect the returned object graph.
Therefore it's recommended to create an opportunity in Insightly using the web interface. Then GET that opportunity JSON using the Insightly2 gem Insightly2.client.get_opportunity(id: 1)
. Once you have the JSON you can just send the same JSON as you are doing with Insightly2.client.create_opportunity(opportunity: opportunity_attributes)
. You will see the opportunity creation should work as long as opportunity_attributes contains the JSON returned by the GET. From there you just build a serializer that generates JSON which looks like what you already have from the GET. If you're using Rails then Active Model Serializers will be the way to go.
By the way I understand Insightly are very close to releasing a new version of their API which will make this gem obsolete. Depending on urgency you might want to hold off and make use of their new API. @brianinsightly can possibly give you more information on its release date.
I know this post is older but I am getting an error Insightly2::Errors::ClientError
how do I debug this error
Insightly2.api_key = ENV["INSIGHTLY_API_KEY"]
Insightly2.client.get_opportunities
It was working earlier, it does this randomly
Firstly, thank you dior001, et al for creating this gem! I'm trying to get the API set up for our company.
This works great, and I am able to access our data. However, when I then try:
I get a Insightly2::Errors::ClientError I'm not really sure how to debug from here, and any help would be appreciated. I am admittedly something of noob, and I did notice your note about serialization of JSON, but haven't found a solution down that path so far.