Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Use Scrptrunner call REST API response json error

Vũ Tuấn Anh (VF-IT-KVH) November 12, 2024

Code

def post(def hostUrl, def endpoint, def body, def token) {

    if (hostUrl.toString().contains('&') || hostUrl.toString().contains('?')) {
        log.error 'The parameters of the endpoint must be included in the query variable'
        return
    }
    def client = new RESTClient(hostUrl)
    client.setHeaders([
            'Accept'       : ContentType.JSON,
            'Authorization': "Bearer $token"
    ])
    client.handler.success = { HttpResponseDecorator response, json ->
        json
    }
    client.handler.failure = { HttpResponseDecorator response ->
        log.error response.entity.content.text
        [:]
    }
    client.post(
        path: endpoint,
        body: body,
        contentType: ContentType.JSON
    )
}

JSON reponse

 

ResponseMsg: [
        MSGCODE: 0,
        MSGTYPE:S,
        MSGINFOR:Hold vehicles completed,
        MSGDATA: [
            [  
                KEY:HSP-1099,
                VAL: 5,
                DESC: DONE
            ],
            [
                KEY:HSP-1100,
                VAL: 5,
                DESC: DONE
            ],
            [
                KEY:HSP-1101,
                VAL: 5,
                DESC: DONE
            ]
        ]
    ]

1 answer

1 accepted

0 votes
Answer accepted
Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 13, 2024

So what exactly is your question?

Vũ Tuấn Anh (VF-IT-KVH) November 27, 2024

I fied it.

Thanks

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira cloud certification, managing jira projects, jira project administration, jira cloud exam, atlassian certification, agile project management, jira workflows, jira permissions, jira training, jira cloud skills, atlassian learning

Become a Certified Jira Service Project Expert 🦸🏻‍♂️

Validate your expertise in managing Jira Service Projects for Cloud. Master configuration, optimize workflows, and manage users seamlessly. Earn global 🗺️ recognition and advance your career as a trusted Jira Service management expert.

Get Certified! ✍️
AUG Leaders

Atlassian Community Events