[Solved] How to call a generic request from API?


#1

Hi,

I would like to build a generic API with Automation Engine.
Followinf @jhardy blog post So I created an instance /System/Request/MyAPI and when I try to call it, it just keeps calling /System/Event/request_created#create. I understand that an event is generated when call the REST API, but no data from my request is passed to $evm.root.

I call the API with the following code:

http = HTTPClient.new
http.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
uri = "https://cfme001.lab.evenit.info/api/automation_requests"
http.set_auth(uri, 'admin', 'smartvm')
http.www_auth.basic_auth.challenge(uri)

headers = { "Content-Type" => "application/json", "Accept" => "application/json,version=2" }
content = {
  :version => '1.1',
  :uri_parts => [{
    :namespace => 'System',
    :class => 'Request',
    :instance => 'GenericApi',
    :message => 'create'
  }],
  :parameters => [{
    :auto_approve => 'true',
    :method => 'helloworld',
    :args => {
      :arg1 => 'value1',
      :arg2 => 'value2',
      :arg3 => 'value3'
    }
  }]
}

puts http.post(uri, content.to_json, headers).content

Any hint ?


#2

Ok, so my eyes are the true problem :confused:
The content missed a requester section :

content = {
  :version => '1.1',
  :uri_parts => [{
    :namespace => 'System',
    :class => 'Request',
    :instance => 'GenericApi',
    :message => 'create'
  },
  :parameters => {
    :method => 'helloworld',
    :args => {
      :arg1 => 'value1',
      :arg2 => 'value2',
      :arg3 => 'value3'
    }
  },
  :requester => {
    :user_name => 'jdoe',
    :auto_approve => true
  }
}

#3

Cool. So it works now?


#4

Yep. My automate entrypoint is called and I can start building my own API based on MIQ engine :wink:


#5

You know what the next step is, right? http://github.com/ManageIQ/manageiq_depot && http://manageiq.org/depot/ :slight_smile:


#6

Indeed yes. I still need time to write down my ideas, but the first step is here.


#7

awesome - thanks! Great to see people making progress.