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

Can't get API to work at all #82

Open
lorenzsell opened this issue Aug 22, 2021 · 5 comments
Open

Can't get API to work at all #82

lorenzsell opened this issue Aug 22, 2021 · 5 comments

Comments

@lorenzsell
Copy link

lorenzsell commented Aug 22, 2021

I'm having all sorts of issues with the API and can't tell if it's just me or if the documentation is out of date.

First, I'm unable to connect with:

client = ::ActiveCampaign::Client.new(
        api_url: 'YOUR-ENDPOINT', # e.g. 'https://youraccount.api-us1.com/api/3'
        api_token: 'YOUR-API-KEY')

I have to use api_endpoint and api_key instead of api_url and api_token and it doesn't work at all with the /api/3 endpoint. I have to point it at /admin/api.php. This isn't documented anywhere. I had to parse it together from support requests and a lot of hacking.

Once I'm actually connected to the API, I can hardly make any calls. For example, I've tried every possible variation I can think of to retrieve all lists:
client.lists, client.get_lists, client.list.

They all generate a version of:

client.show_lists => 
NoMethodError: undefined method `show_lists' for #<ActiveCampaign::Client:0x00007fbaede2b6c0>

The only thing that generates a response is client.list_list which gives me the following:

=> {"result_code"=>0,
 "result_message"=>"Failed: Nothing is returned",
 "result_output"=>"json",
 "results"=>[]}

@jmburges
Copy link

same!

@shenst1
Copy link

shenst1 commented Sep 15, 2021

same

@jasonfb
Copy link

jasonfb commented Nov 2, 2021

@lorenzsell @jmburges @shenst1 -- I think the problem here is that master branch is not consistent with what is pushed to Rubygems.

see last known published gem https://github.com/mhenrixon/active_campaign/tree/v0.1.16

sync_contact became contact_sync
add_contact became contact_add
etc

@jasonfb
Copy link

jasonfb commented Nov 2, 2021

this seems like all developer confusion to me. I went down these same rabbit holes, explained here: #84

@lorenzsell @jmburges @shenst1

as well, you must take note that the comment in the setup has the critical piece of hidden information: /admin/api.php must be added to your active campaign subdomain for it to work (this is all working on the V1 API)

client = ::ActiveCampaign::Client.new(
api_endpoint: 'https://[YOUR ACTIVE CAMPAIGN DOMAIN]/admin/api.php', # e.g. 'https://yourendpoint.api-us1.com/admin/api.php'
api_key: '[YOUR-API-KEY]')

@mhenrixon -- as a point of feedback, your code has lots of comments with important hidden details, which other developers (like me and the ones above) won't read when we're moving quickly. I'd recommend making some of this stuff more explicit in the actual code so that our editors show it as a color we should pay attention to (and not grey, signaling irrelevance.) just to make it easier to grok for people new to the gem.

@jasonfb
Copy link

jasonfb commented Nov 2, 2021

also to debug the actual API, I had to do a little low-level monkey patching. Since the published version of the gem is currently old and I see that master is refactored, I won't bother making a pull request. As well, I see that on the new gem code there are already begin/rescue to handle this.

however, when working on v0.1.16, you will get crashes on client.rb line 71 if the JSON fails to parse.

To debug it, I had to re-write the method like to see the actual responses from the API:

I would highly recommend patterns like this when making wrappers because you can't anticipate all of the things that can (will) go wrong with these responses and it's probably best just to leave the responses spit back to us the developer to figure out where went wrong.

 def request(method, api_method, data)
      req = create_request method, api_method, data
      response = HTTPI.send(method, req)
      begin
        response = JSON.parse(response.body)
      rescue StandardError => e
        puts "*********  There was an error parsing the response from ActiveCampaign: #{response.inspect}"
        raise(e)
      end

      normalize(response)
    end

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

4 participants