Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to debug Insightly2::Errors::ClientError #31

Open
cabezud opened this issue Nov 3, 2015 · 2 comments
Open

How to debug Insightly2::Errors::ClientError #31

cabezud opened this issue Nov 3, 2015 · 2 comments

Comments

@cabezud
Copy link

cabezud commented Nov 3, 2015

Firstly, thank you dior001, et al for creating this gem! I'm trying to get the API set up for our company.

Insightly2.api_key = ENV["INSIGHTLY_API_KEY"]
Insightly2.client.get_opportunities

This works great, and I am able to access our data. However, when I then try:

opportunity_attributes = {"OPPORTUNITY_NAME"=>"Test123"}
Insightly2.client.create_opportunity(opportunity: opportunity_attributes)

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.

@dior001
Copy link
Contributor

dior001 commented Nov 6, 2015

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.

@kftwotwo
Copy link

kftwotwo commented Mar 6, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants