Search code examples
rubyjsonrest-client

How do i pass parameters as well as set headers with rest_client in http api call


With rest_client gem

I have to pass parametes and set http headers as well. parameters- {"module"=>{"id"=>376373}, "name"=>"test workflow", "playbooks"=>[{"name"=>"shell_book.yml"}]} headers- {Accept => application/json, content-type => application/json, mode => agentless}

please suggest how do i do this.

My code looks like this- RestClient.put(@@host+'/workflow/agentless', {:params => {"module"=>{"id"=>376373}, "name"=>"test workflow", "playbooks"=>[{"name"=>"shell_book.yml"}]} })


Solution

  • The third parameter is the headers hash.

    Try the code below with your values:

    response = RestClient.put(url, request, :content_type => :json, :accept => :json)