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