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

StackOverflow https://stackoverflow.com/questions/21823219

  •  12-10-2022
  •  | 
  •  

Pergunta

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"}]} })

Foi útil?

Solução

The third parameter is the headers hash.

Try the code below with your values:

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

Outras dicas

I was missing params.to_json earlier... following worked for me.

RestClient.put(@@host+'/workflow/agentless', params.to_json, :content_type => :json, :accept => :json, :mode => :agentless)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top