2

Is there a way to explore the API from the command line instead of going to mycivicrmsite.localhost/civicrm/api in a web browser?

I wasn't able to learn much from the cv help. For example, you can cv api contact.get... but what else can you cv api contact.do?

I know I can just go over to the web browser and pull up that page, but I just wanna hang out in my terminal :)

  • 3
    Just curious - why? The API Explorer guides you in constructing an API call and shows you the syntax in the various supported languages and commands. It also has examples and code docs built in. – Aidan Aug 29 '18 at 11:20
1

The graphical api explorer actually fetches all its information about the api from the api. Since the CiviCRM api is available from the command line, you can explore it using the same methods.

  • Fetch the list of entities:

    $ cv api Entity.get

  • List available actions for an entity:

    $ cv api Activity.getactions

  • Get fields for an entity/action:

    $ cv api Activity.getfields action=create

  • Is this the extent of information available from commandline? I'd love to be able see the available entities, actions, and keys and what they can take for values. – alec Sep 1 '18 at 4:36
  • Updated my answer – Coleman Sep 1 '18 at 12:13
  • Oh that's great, thanks! That'd be super helpful for first orienting to using cv if that was printed in the output of cv api --help. I think I'm going have a lot of questions around this and I'm not sure how much I should post those here. It looks like there's not much "Getting started with CiviCRM's CLI" tutorial around, I'd be glad to contribute towards one. – alec Sep 1 '18 at 16:10
  • I guess I should explore before asking any more questions, as I'm answering them myself. cv api Setting.get | peco is a helpful way to explore all that json output. Thanks again! – alec Sep 1 '18 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.