How to convert web response to json

Marina Vital July 19, 2023

Hi guys,
We have a project in JSM in instance X that receives ticket openings through emails sent by customers. The body of the email can arrive with various types of formatting (bold text, paragraphs, tables, signature, links), we do not have a standard. Through Jira automation we want to take the data from the "Description" field and send a web request (API) to create a new ticket in the instance Y.

I am doing a GET and retrieving the response with the smart value {{webResponse.body.fields.description}}, but it does not return me in json format for me to do the POST (creation of the ticket in the other instance Y).

 

I'm getting this:

{version=1, type=doc, content=[{type=paragraph, content=[{type=text, text=.....}}

 

When I need this:

{
"version": 1,
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"type":.........}


Body Json

2023-07-19_17-32.png

 

Error:

2023-07-19_17-33.png

 

Does anyone have any other solution? I just need the automation to copy the description of the source ticket and by making the API call I can create a new ticket in another instance.

 

1 answer

1 accepted

0 votes
Answer accepted
Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 19, 2023

Have you tried to convert it to a JSON string using the asJsonString function? 

Marina Vital July 19, 2023

Hi @Mikael Sandberg ,

Yes, I tried, but I don't get any return in the log when I use {{webResponse.body.fields.description.asJsonString}}

Is there something wrong in the syntax?

2023-07-19_18-16.png

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 19, 2023

Hmm, the web response should already be a JSON format, based on the screenshot you included above it is coming back as a JSONStringify format. So that leads me to believe that when you are using it in the custom data field it is missing a character. I would recreated the data in a JSON parser to see what could be wrong.

Marina Vital July 20, 2023

Hi @Mikael Sandberg ,

Thanks, really the previous error was due to a syntax problem in the json. Now I get a new error, I believe that the automation is not understanding the format of the data I am inputting through the smart value.


2023-07-20_17-27.png

 

He expects this format:

2023-07-20_17-32.png

Mikael Sandberg
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 20, 2023

I think that document format is only for Jira Software. Assuming you are using the JSM create customer request endpoint you would not need to define the document format if you look at the documentation for it.

Marina Vital July 21, 2023

Hi @Mikael Sandberg ,

After a few more attempts I came up with a solution, I would like to thank you for your support.

After a few more attempts I arrived at a solution, I would like to thank you for your help, it was important for me to succeed.

Basically, I created a variable converting the value of the description field to an string json and then used the variable to make the post. For some reason when I tried this the other time without the variable, I got an error on the request.

2023-07-21_18-02.png

2023-07-21_18-02_1.png

 

Now I will work on getting the attachments.


Thank you very much!

Like # people like this
Malcolm Hinds May 1, 2024

Hi @Marina Vital  how did this work for you? I have the same problem, and when I assigned a variable to {{issue.description.asJsonString}} it just returns with the description in quotes, doesn't covert to the required Atlassian Document format?

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events