Below is the JSON data which contains rich text/wiki text. I want to pass this data to to one of the issues in Jira through REST API. Here Java is the technology, I am using.
{"update":{"summary": [{"set": "CRF-397 – For Virgin Mobile, alert must be sent via email when Tier Mismatch exception is encountered."}]},"fields":{"description":{"set":"*Clients Impacted** Virgin Mobile *Background Information*<br>All UK schemes are experiencing at different levels some issues of:* Customers being billed on the wrong premium* Excess Fees paid at point of claim do not correspond to what has been communicated to the customer at the point of sale.* Welcome packs not being issued due to a mismatch *CRF Scope*<br>The scope of this project consists of identifying whenever a new device is communicated to Asurion by a client system and ensuring the data in each of those instances is validated to confirm that the device premium and excess fees are correctly aligned.*User Story Scope*<br>While doing enrollment if any record goes into exception due to Tier is match we have to send consolidated list of such records via email so that Asurion Team can communicate with Virgin Mobile to resolve the Tier Mismatch issues.*Requirement** An email alert must be sent when Tier Mismatch exception is encountered.* Flag based development must be done for triggering an email.* Email must be sent to Client Service, SCM and BI teams* Recipient email IDs must be configurable.* Exception list must contain below records:- * The list of devices for which there was an exception * The Feature Code sent by Virgin Mobile * The feature code configured in Client Convention for the given device*"}}}
Above JSON I am storing in jiraUpdateFromBuilder.
I am calling PUT method to update description in Jira, as below.
String _jiraUrl = applicationProperties.get(Constants.JIRAURL)
+ "/rest/api/2/issue/" + reference;
String _jiraUser = applicationProperties.get(Constants.JIRAUSER);
String _jiraPwd = applicationProperties.get(Constants.JIRAPWD);
String auth = new String(Base64.encode(_jiraUser + ":" + _jiraPwd));
int statusCode = invokePutMethod(auth, _jiraUrl.trim(),
jiraUpdateFromBuilder.toString().trim());
public static int invokePutMethod(String auth, String url, String data) {
int statusCode = 0;
try {
Client client = Client.create();
WebResource webResource = client.resource(url);
ClientResponse response = webResource
.header("Authorization", "Basic " + auth)
.type("application/json").accept("application/json")
.put(ClientResponse.class, data);
statusCode = response.getStatus();
return statusCode;
} catch (Exception e) {
Constants.ERROR.info(Level.INFO, e);
}
return statusCode;
}
Doing so, I am unable to update description of issue in Jira, through any REST API, because here getting status other than 201. And the same problem is with all the field of an Issue in JIRA which contains rich text. Kindly let me know if JRJC can help else if I need to change in JSON or any other approach.
Your json looks like this:
{
"update": {
"summary": [
{
"set": "CRF-397 ..."
}
]
},
"fields": {
"description": {
"set": "..."
}
}
}
But the "fields" part does not require to use the 'set' keyword, so it should be something like this:
{
"update": {
"summary": [
{
"set": "CRF-397 ..."
}
]
},
"fields": {
"description": "..."
}
}
If you check the documentation for the PUT /issue REST resource, you'll see that it mentions this:
Specifying a "field_id": field_value in the "fields" is a shorthand for a "set" operation in the "update" section.
Field should appear either in "fields" or "update", not in both.
Also, you've mentioned that your response status code was 400, which means it's a bad request. The response body will probably contain more detail about what is wrong, so it's best to log that as well.
Regarding this error:
Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value\n at [Source: org.apache.catalina.connector.CoyoteInputStream#20e841d2; line: 1, column: 187]
Your description value contains newlines, but it's not allowed to use those in a json string directly. You'll have to escape those. See this post for an example.
The Jira documentations and these answers seem to be outdated. With API version 3 of Jira. (API docs to edit issue)
Updating the description of an Issue in Jira:
HTTP Method: PUT
HTTP URL: https://cognitedata.atlassian.net/rest/api/3/issue/{issueIdOrKey}
Request Body:
{
"fields": {
"description": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "add your description here"
}
]
}
]
}
}
}
If you use a different request body, you will get the following error:
{
"errorMessages": [],
"errors": {
"description": "Operation value must be an Atlassian Document (see the Atlassian Document Format)"
}
}
Related
I am trying to post a text on LinkedIn using UGC through Postman.
Here is my request body:
{
"author": "urn:li:person:{uid of my account}",
"lifecycleState": "PUBLISHED",
"specificContent": {
"com.linkedin.ugc.ShareContent": {
"shareCommentary": {
"text": "Hello World! This is my first Share on LinkedIn!"
},
"shareMediaCategory": "NONE"
}
},
"visibility": {
"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
}
}
Note: uid of my account is fetched through - https://api.linkedin.com/v2/me
The response I am getting is:
{
"message": "ERROR :: /author :: \"urn:li:person:oQRNppEnm\" does not match urn:li:company:\\d+|urn:li:member:\\d+\n",
"status": 422
}
Can anyone please help out here?
I had such a mistake. I used wrong value from https://api.linkedin.com/v2/me request answer. You need to add id in your request query if you haven't already,
for example
https://api.linkedin.com/v2/me?projection=(id,localizedFirstName,localizedLastName)
also you need to use value from id field of JSON answer:
{"id\":\"XyyyyXXXXX\"}
It will be some kind of value with numbers and letters, not just numbers.
i make a post to an api with rest assured. and than i try to make sure expected data from responsed data ,
but i got some errors like this -> "java.lang.IllegalArgumentException: The parameter "data" was used but not defined. Define parameters using the JsonPath.params(...) function"
my code:
String payload_data = "{" +
"\"Time\":1638057600, " +
"\"exampleType\":example, " +
"\"Id\":[2]}";
RestAssured.defaultParser = Parser.JSON;
given().
contentType(ContentType.JSON).
body(payload_data).
when().
post(api_url).
then().
statusCode(200).
body("data.examples.2.exampleData", equalTo("33"));
}
my json data
{
"success": true,
"data": {
"examples": {
"2": {
"ex_data": 0,
"exampleData": 33,
"data_ex": 0,
}
}
}
First, I tested path "data.examples.2.exampleData" with your json, it works fine. No problem.
You made some mistakes here.
Your payload is invalid json.
{
"Time": 1638057600,
"exampleType": example, //it must be number or String with double quote
"Id": [
2
]
}
You are comparing 2 things with different data types.
"data.examples.2.exampleData" --> int 33
equalTo("33") --> String "33"
Fix: body("data.examples.2.exampleData", equalTo(33));
I am trying user authentication with firebase in java using spring framework. When ever I try to authenticate a user using the provided emailId and password I am getting a 400 Error, but the emailId does exist in the fireBase authentication as well as in the firebase realtime database page. I am also able to retrieve data using uuid which is available in fireBase authentication web page.
My code:
String googleAuthUrl =
env.getProperty("google.auth.identity.toolkit.url") +
env.getProperty("google.auth.identity.toolkit.key");
Client client = Client.create();
WebResource webResource = client.resource(googleAuthUrl);
ClientResponse response = webResource.accept("application/json").type("application/json")
.post(ClientResponse.class, inputJson);
Integer responseCode = response.getStatus();
String responseBody = response.getEntity(String.class);
logger.info("Google response : {}", responseBody);
// ...
My input :
{
"email": "abc#gmail.com",
"password":"test123"
}
Exception encountered:
Google response : {
"error": {
"code": 400,
"message": "EMAIL_NOT_FOUND",
"errors": [
{
"message": "EMAIL_NOT_FOUND",
"domain": "global",
"reason": "invalid"
}
]
}
}
Can anyone explain the reason for this exception and how to overcome the problem ! Instead of making a REST call is there an SDK available for user authentication ?
I just had a similar problem with same library but in flutter.
The problem was that I was sending the email with a white space at the end...
So, I don't know if you solved it but a trim() function can solved it, if is the case sure
I faced following problem:
I wanna get list of changes from gerrit repository using this api function https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes
When I sent GET request in browser I got response
[
{
"id": "business~develop~I65d58a2345346cb35a0ecbb63d6ed896c7",
"project": "business",
"branch": "develop",
"hashtags": [],
"change_id": "I65d58a2a045645636cb35a0ecbb63d6ed896c7",
"subject": "Leader property deleted from organizational unit classes. Org unit\u0027s employees cascad type removed. Employee\u0027s roles amount limited by 1 in orgUnit.xsd. Employees identifiers changed in orgUnit.xml. Updated domain model. DataUploadRestService created. Emp",
"status": "NEW",
"created": "2015-05-12 14:31:48.226000000",
"updated": "2015-07-07 07:34:35.195000000",
"mergeable": true,
"insertions": 3100,
"deletions": 1358,
"_number": 589,
"owner": {
"_account_id": 1003473
}
}
]
But when I send GET request using RestEasy or other way to send request using Java code:
try {
final ResteasyClient client = new ResteasyClientBuilder().build();
final ResteasyWebTarget target = client
.target("https://gml-jbpm.gomel.iba.by/gerrit/changes/");
String response = target.request().get(String.class);
final JSONArray array = new JSONArray(response);
System.out.println("RestEasy response: " + array);
} catch (final Exception e) {
e.printStackTrace();
}
I get empty response:
[]
How to solve this problem? Why I get empty JSONArray?
I'm having trouble passing a complex json object in angularjs with $http.post. I'm keep getting a 400 bad request error sent back from the server saying the request was syntactically incorrect. I believe it has something to do with the array since it passes fine when i don't include it.
json i'm passing.
{
customer: {
firstName: "John",
lastName: "Doe",
street: "1234 South Dr",
city: "Detroit",
state: "MI",
zip: "12345",
phone: "123-321-1234",
email: "EMAIL#GMAIL.COM"
},
order: {
orderDate: "06-16-2015",
registerNum: "1",
transactionNum: "7820",
deliveryStatusID: 1,
notes: "Hold order until July",
items: [
{skuID: "1234568",
skuDescription: "Order item 1",
qty: "4",
itemStatusID: 1,
itemStatusDescription: "Backorder"
},
{skuID: "7387491",
skuDescription: "Order item 2",
qty: "1",
itemStatusID: 1,
itemStatusDescription: "Flagged"
}
]
}
}
angular service function
this.addOrder = function(new_order) {
return $http.post(base + "/add", new_order);
};
Spring MVC controller method
#RequestMapping(value="/add", method=RequestMethod.POST)
public void addOrder(#RequestBody CustomerOrder customerOrder) {
System.out.println("----CUSTOMER-INFO----");
System.out.println(customerOrder.getCustomer().getFirstName());
System.out.println(customerOrder.getCustomer().getLastName());
System.out.println("");
System.out.println("----ORDER-INFO----");
System.out.println(customerOrder.getOrder().getOrderID());
System.out.println(customerOrder.getOrder().getOrderDate());
}
The problem only seems to occur when I pass the items array in the json. I've passed the same json object without the items array and it works fine. The format of the json is being sent in the same format that gets returned whenever I GET an order with my angularjs service method so I'm really not sure as to where I'm going wrong with this.
If I need to provide more code please let me know. I appreciate any effort in helping me out.
Thank you.
Jason
Well after struggling to find my error in this problem, I finally found a solution. I thought I'd share how I debugged and fix this problem in case someone else is in a similar situation as I was.
After trying every possible way of sending my data in angular to the server and continually getting the same HTTP 400 error, I decided to send the json as a string and accept the json as a string in my spring mvc controller like this.
angular service method:
this.addOrder = function(new_order) {
return $http.post(base + "/add", angular.toJson(new_order));
};
spring controller
#RequestMapping(value="/add", method=RequestMethod.POST, consumes="application/json")
public void addOrder(#RequestBody String json) {
}
From here I simply took the json passed in and used the Jackson ObjectMapper to convert the json string to my POJO like this.
mapping json string to pojo
#RequestMapping(value="/add", method=RequestMethod.POST, consumes="application/json")
public void addOrder(#RequestBody String json) {
ObjectMapper mapper = new ObjectMapper();
try {
CustomerOrder order = mapper.readValue(json, CustomerOrder.class);
System.out.println(order.getCustomer().getFirstName() + " " + order.getCustomer().getLastName());
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
After doing this and running my code, I would get an UnrecognizedPropertyException on a field in my Items class when trying to bind the items json to the List in my Order class. It was just a simple mispelling on the json side and I completely missed it. After correcting this, jackson mapped everything correctly and I no longer get this HTTP 400 Error The request was syntactically incorrect.
Another thing to note is that if you pass your object as a string in angular using the JSON.stringify you may encounter this same exception on hashKey field in the JSON object. The hashKeys are used by angular to monitor changes. I believe you can use a jackson annotation to ignore unknown fields or you can simply use angular.toJson instead which will remove all the hasKey/values for you which is what I did.
Just formatted the Json in a better way. Try this if it helps. Also, post the java classes if possible:
{
"customer": {
"firstName": "John",
"lastName": "Doe",
"street": "1234 South Dr",
"city": "Detroit",
"state": "MI",
"zip": "12345",
"phone": "123-321-1234",
"email": "EMAIL#GMAIL.COM"
},
"order": {
"orderDate": "06-16-2015",
"registerNum": "1",
"transactionNum": "7820",
"deliveryStatusID": 1,
"notes": "Hold order until July",
"items": [
{
"skuID": "1234568",
"skuDescription": "Order item 1",
"qty": "4",
"itemStatusID": 1,
"itemStatusDescription": "Backorder"
},
{
"skuID": "7387491",
"skuDescription": "Order item 2",
"qty": "1",
"itemStatusID": 1,
"itemStatusDescription": "Flagged"
}
]
}
}