Forum Discussion

zsousa's avatar
zsousa
Contributor
8 years ago
Solved

Using groovy how to call an existing endpoint and pass in 2 parameters

I have an existing endpoint request, what I need to do is call an existing  endpoint request and pass in 2 parameters using Groovy.

  • I figured it out see below for my example

     

     

    import groovyx.net.http.HTTPBuilder
    import static groovyx.net.http.ContentType.*
    import static groovyx.net.http.Method.*


    def r = "[1,"createCompany",1,1,{"1":{"rec":{"3":{"str":"2017-02-07"},"4":{"str":"US"},"5":{"rec":{"1":{"i64":255130}}},"6":{"tf":0},"7":{"tf":1},"8":{"i64":1},"9":{"str":"QATestCompany_X14864936528160001"},"10":{"str":"_newcompany"},"11":{"i64":1}}}}]"

    def http = new HTTPBuilder('https://myservice.service.us.com/')
    http.request( POST ) {
        uri.path = 'clientservice/thrift/json'
        requestContentType = "application/json"
        body =  r

        response.success = { resp ->
            log.info "POST response status: ${resp.statusLine}"

        }
    }

3 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    It is really unclear. Would you mind explain with more specific details? If possible along with a screen shot?
    • zsousa's avatar
      zsousa
      Contributor

      I will try to explain.

       

      so I have predefined endpoints under the  "Projects" tab.

       

      normally, I can create a REST request and select that endpoint and all works fine.

       

      but lets say I wanted to run a request, through Groovy only is there a way to do this ?

      • zsousa's avatar
        zsousa
        Contributor

        I figured it out see below for my example

         

         

        import groovyx.net.http.HTTPBuilder
        import static groovyx.net.http.ContentType.*
        import static groovyx.net.http.Method.*


        def r = "[1,"createCompany",1,1,{"1":{"rec":{"3":{"str":"2017-02-07"},"4":{"str":"US"},"5":{"rec":{"1":{"i64":255130}}},"6":{"tf":0},"7":{"tf":1},"8":{"i64":1},"9":{"str":"QATestCompany_X14864936528160001"},"10":{"str":"_newcompany"},"11":{"i64":1}}}}]"

        def http = new HTTPBuilder('https://myservice.service.us.com/')
        http.request( POST ) {
            uri.path = 'clientservice/thrift/json'
            requestContentType = "application/json"
            body =  r

            response.success = { resp ->
                log.info "POST response status: ${resp.statusLine}"

            }
        }