1
votes

I want to call a REST API using a Scriptrunner endpoint.

The URL below has the parameters Plant and PartNumber.

https://exex.example.com/API/Engineering/Analysis/Validate?Plant=EAES&PartNumber=R170025Y001001

When I call the URL from the REST endpoint, I want to update the status of Plant and PartNumber in other applications. How can I do that?

  • I want the output circled below when I run the REST endpoint Postman screenshot
1

1 Answers

0
votes

You can try with below script,(modify according to your values and method type)

    import groovyx.net.http.HTTPBuilder
    import static groovyx.net.http.ContentType.*
    import groovyx.net.http.ContentType
    import static groovyx.net.http.Method.*
    import groovy.json.JsonSlurper
    import net.sf.json.groovy.JsonSlurper
    
    def http = new HTTPBuilder('https://YOUR REST URL')
    http.request(POST) {
        requestContentType = ContentType.JSON
        body =  [username: 'USERNAME', password: 'PASSWORD']
        response.success = { resp, JSON ->
         return JSON
        }
        response.failure = { resp ->
         return "Request failed with status ${resp.status}"
        }
    }