160
Views
22
Comments
Solved
Single Text to JSON Format Convertion
Question
Application Type
Service

I need to pass single text which is username in text format need to be converted to JSON format and pass it to Jira rest api.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Thanks for the trace. Unfortunately, it doesn't tell us much more, it shows you posting a 7-character body, and you get a 400 in response ("bad request"), unfortunately without any body with an error message.

However, checking the documentation, it seems that you need to send a JSON string, which means you need to enclose the text in double quotation marks. So instead of sending:

kau2cob

you need to send

"kau2cob"

Looking at your post again, that's exactly what you do there, since "body content" is the literal content, not an OutSystems quoted string :).

EDIT: there seems to be some more requirements, like setting both the Content-Type header (which is already set) and the Accept header (which is not), so you may need to add the latter. The easiest way to do that is to add a header Input Parameter to the method.

2022-08-03 04-32-50
Ravi Punjwani

Hi Sowndhar,

What is the JSON format that you want to use? Is there any name of the property you want to use in your JSON string?

Like, { "username":  "sowndhar.s@outsystems.com" }

Here username is the property / attribute name. What is the exact format of string you want to output?

UserImage.jpg
Sowndhar S

Hi Ravi,

rest/api/2/issue/{issueId}/watchers

For this api,I need to send just username as string.The outsystems automatically creates request datatype as text but when I input this string it shows error 400.So I thought this input need to be converted to JSON format.

But in test area it is working correctly.

2022-08-03 04-32-50
Ravi Punjwani

Hi Sowndhar,

In this case you don't need a JSON string, it is just a plain string containing username.

UserImage.jpg
Sowndhar S

Yeah,Ravi.I don't need JSON String.But when I give input userId as plain text it shows 400 error.

2022-08-03 04-32-50
Ravi Punjwani

You will need to find out what it describes further than just 400 error.

HTTP 400 Bad Request

Usually APIs provide more information about what are you sending incorrectly. Find out more information from the Integration Logs by finding out your REST API consume call in that list.

UserImage.jpg
Sowndhar S

I send the input through form.API returns http error code only and it didn't show any error message.

I customize the response.Here it is


.



2022-08-03 04-32-50
Ravi Punjwani

You can see the full error response without modifying or customizing. Just login to the service center and visit Monitoring > Integration Logs and find your API call in that list.

It gives you all details about this error.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

That's not quite true, you need to increase the logging level of the API, otherwise you won't see much detail.

2022-08-03 04-32-50
Ravi Punjwani

Hi Killian,

Increasing the logging level may be required for the API calls which were successful. As she already mentioned the issue resulted in an exception. I believe it would still give all error details even if the logging level is not modified.

UserImage.jpg
Sowndhar S
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

That is not true. To see any details of the actual call, you need to set it at least to "Troubleshoot". Otherwise you will not get details (other than the call stack, which is useless).

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Please check the post I linked. The error stack is useless here. You need the details from the integration logging to see what you sent to Jira and what the response is.

2022-08-03 04-32-50
Ravi Punjwani

Hi Sowndhar,

It will require integration log details not the standard Error Log. From the integration log details, you also find a button at the bottom, to download the HTTP Trace of that call. Please share that information here.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

But you won't find that button, unless you have increased the logging level, that's what I was saying.

2022-08-03 04-32-50
Ravi Punjwani

I hope Sowndhar might have already raised the error logging level by now :)

Let's wait for more logs.

UserImage.jpg
Sowndhar S
HicmtsAppsIntranetBosch.PostWatchers.trace.txt
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Thanks for the trace. Unfortunately, it doesn't tell us much more, it shows you posting a 7-character body, and you get a 400 in response ("bad request"), unfortunately without any body with an error message.

However, checking the documentation, it seems that you need to send a JSON string, which means you need to enclose the text in double quotation marks. So instead of sending:

kau2cob

you need to send

"kau2cob"

Looking at your post again, that's exactly what you do there, since "body content" is the literal content, not an OutSystems quoted string :).

EDIT: there seems to be some more requirements, like setting both the Content-Type header (which is already set) and the Accept header (which is not), so you may need to add the latter. The easiest way to do that is to add a header Input Parameter to the method.

UserImage.jpg
Sowndhar S

That's correct.I need to add double quotation mark in input also.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Glad I could help. The takeaway here is: check the integration logging to see what you sent, and match that with the API specification. This will allow you to find the errors and correct them.

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Sowndhar,

If you want to consume the Jira REST API, you need to follow the Jira specifications. Thinking "I get a 400, do I need it in JSON?" is not the way to go. Also, you'll almost never need to convert something to JSON yourself when consuming REST APIs, as OutSystems does that for you.

That said, since you are connecting to JIRA, did you check out the JIRA Connector in the Forge? Even if you don't want to use a Forge asset, you could check what's inside.

UserImage.jpg
Sowndhar S

Hello Kilian,

Thanks,I will check out the Jira connector

UserImage.jpg
Sowndhar S

Thank you so much @Kilian Hekhuis  and @Ravi Punjwani for your time and this valuable answers.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.