Getting Bad request 400 using REST API POST Call ( Using Salesforce Apex)

Vigneshwar Kotha November 3, 2023

I am getting a Bad Request with an Error Code 400 issue. find the below Json Request.

Working in UAT but not in production. Please let me know if any suggestions.

{
"fields": {
"summary": "Testing 123 - Push to Jira",
"reporter": {
"id": "5fb422c74a09640069d1***"
},
"project": {
"id": "10297"
},
"issuetype": {
"id": "10004"
},
"description": {
"version": 1,
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Problem Description:",
"marks": [
{
"type": "strong"
}
]
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Delete when done"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Steps to Reproduce:",
"marks": [
{
"type": "strong"
}
]
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "N/A"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Desired Result:",
"marks": [
{
"type": "strong"
}
]
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "N/A"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Actual Result:",
"marks": [
{
"type": "strong"
}
]
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "N/A"
}
]
}
]
},
"customfield_10204": "PR-0004956",
"customfield_10172": {
"value": "Moderate"
}
}
}

1 answer

0 votes
Jehan Bhathena
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 7, 2023

Hi @Vigneshwar Kotha ,

What API are you trying to use here?

Perhaps you can explain the use case a little bit, it may help identify the cause or even get a suggestion to another approach

Vigneshwar Kotha November 15, 2023

Hi Jehan,

Thank you for Response.

Actually, I am trying to create a Jira issue from Salesforce. Able to create JIRA issue from other sandboxes but getting issue in production. This is the API am using.

API: Endpoint=https://**.atlassian.net/rest/api/3/issue, Method=POST

This is the Error : Status=Bad Request, StatusCode=400

I have compared my request with production and other sandboxes.It seems same but getting Bad Request Issue.Please find the above request data.

Jehan Bhathena
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 15, 2023

Hey @Vigneshwar Kotha ,

The Post request would need a Body to send, would it be possible to share that as well?

You can paste it as a "code block" In your response so that it is more clear to view.

Vigneshwar Kotha November 15, 2023
{"fields":{"summary":"Testing 123 - Push to Jira","reporter":{"id":"5fb422c74a09640069d1f4a6"},"project":{"id":"10297"},"issuetype":{"id":"10004"},"description":{"version":1,"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Problem Description:","marks":[{"type":"strong"}]}]},{"type":"paragraph","content":[{"type":"text","text":"Delete when done"}]},{"type":"paragraph","content":[{"type":"text","text":"Steps to Reproduce:","marks":[{"type":"strong"}]}]},{"type":"paragraph","content":[{"type":"text","text":"N/A"}]},{"type":"paragraph","content":[{"type":"text","text":"Desired Result:","marks":[{"type":"strong"}]}]},{"type":"paragraph","content":[{"type":"text","text":"N/A"}]},{"type":"paragraph","content":[{"type":"text","text":"Actual Result:","marks":[{"type":"strong"}]}]},{"type":"paragraph","content":[{"type":"text","text":"N/A"}]}]},"customfield_10204":"PR-0004956","customfield_10172":{"value":"Moderate"}}}
Jehan Bhathena
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 15, 2023

Hi @Vigneshwar Kotha ,

I checked the request in Postman, and it works with the body that you provided.

image.png

What custom fields are these? There is a chance that you've got to update the format for them

"customfield_10204", "customfield_10172"

I tried a Multi-line text field and got this response :

image.png

Vigneshwar Kotha November 16, 2023

Those two custom fields are Record Name and Severity. Record Name is text Field and Severity is a picklst field. Both values are getting as expected from salesforce. Fields type and access is same as other instances.

Jehan Bhathena
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 16, 2023

In the last Image I added, you can see an error, perhaps you can share the error you receive when the 400 response is shown.

If you're using an internal Saleforce related UI, and no error is displayed there, you can check the browser network tab to see the error (use F12 to open Dev Tools and then open "Network")

Vigneshwar Kotha November 16, 2023

jiraissue.PNG

This is showing in my logs.

Vigneshwar Kotha November 16, 2023

And I am trying from Postman as well. getting different issues. It is Unauthorised 401 and showing don't have access to the project. but I do have access to the project and I can manually create issues into the project.

Jehan Bhathena
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 16, 2023

Any option to display the Error response along with the error code?

Also, do you configure the API on a desktop app or is this via a Browser app or Curl?

Since each might have a different syntax.

Have you tried firing that API via postman too? Or a different tool perhaps too see if the platform from which you're firing the API may have an issue?

Jehan Bhathena
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 16, 2023

@Vigneshwar Kotha ,

for the postman API you need to use Basic auth.

Uswrname is your Jira username, and password is your API token.

Note: pls delete the previous image since it have your token visible.

Vigneshwar Kotha November 16, 2023

As you said, user Basic Auth with Username and API token. Getting bellow error.

Jiraissue3.PNG

When i remove Reporter from the payload, it is giving success. Can you please suggest ?

Vigneshwar Kotha November 16, 2023

seems like this is the issue.

Like Jehan Bhathena likes this
Vigneshwar Kotha November 16, 2023

I think reporter filed is not set in JIRA right ?

Jehan Bhathena
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 16, 2023

Yupp

That seems like it.

Try removing that from your Salesforce API body too and retry the API

Jehan Bhathena
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 17, 2023

Hey @Vigneshwar Kotha ,

Do let us know how it goes after editing the body of the API request.

https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-post , as the documentation "reporter" field doesn't seem to be needed.\

If this thread helped solve your issue, please mark it as Accepted so that it's more visible to the other community members.

Suggest an answer

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

Atlassian Community Events