By using JMeter jsr223 post processes I am trying to create ticket in Jira I have return some but that code is not working can any one help me to resolve the error is appreciated
Here is the code
import org.apache.http.HttpHeaders;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.jmeter.protocol.http.sampler.HTTPSampleResult;
def assertionResult = prev.getAssertionResults()[0]
if (assertionResult.isFailure()) {
// Set the JIRA REST API endpoint URL
String jiraUrl = "url";
// Set the JIRA account email and API token
String jiraEmail = "mailID";
String jiraApiToken = "Security token";
// Set the JSON payload for creating the JIRA ticket
String jsonPayload = """
{
"fields": {
"project": {
"key": "LEAR"
},
"summary": "Test issue",
"description": "This is a test issue",
"issuetype": {
"name": "Bug"
}
}
}
""";
// Set the HTTP headers for the JIRA REST API request
Map<String, String> headers = [:];
String authString = jiraEmail + ":" + jiraApiToken;
String encodedAuthString = authString.bytes.encodeBase64().toString();
headers.Put(HttpHeaders.AUTHORIZATION, "Basic " + encodedAuthString);
headers.Put(HttpHeaders.CONTENT_TYPE, "application/json");
// Create an HTTP client and POST request
HttpClientBuilder builder = HttpClientBuilder.create();
HttpPost post = new HttpPost(jiraUrl);
post.setHeaders(headers);
post.setEntity(new StringEntity(jsonPayload));
// Execute the JIRA REST API request and get the response
def httpResponse = builder.build().execute(post);
def responseBody = httpResponse.getEntity().getContent().text;
// Log the response details
log.info("Response code: " + httpResponse.getStatusLine().getStatusCode());
log.info("Response body: " + responseBody);
}
Thanks