首页 > 解决方案 > 如何在jira中使用ScriptRunner rest Endpoint调用rest API

问题描述

我想使用 Scriptrunner 端点调用 REST API。

下面的 URL 包含参数PlantPartNumber

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

Plant当我从 REST 端点调用 URL 时,我想更新PartNumber其他应用程序的状态。我怎样才能做到这一点?

标签: jira-rest-api

解决方案


您可以尝试使用以下脚本,(根据您的值和方法类型进行修改)

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

推荐阅读