SivaDev1038 / my-repo

0 stars 0 forks source link

[CSE-64]()How to Fix '422 Unprocessable Entity' when sending a POST request to Redmine API? #114

Open SivaDev1038 opened 1 year ago

SivaDev1038 commented 1 year ago

Atlassian Ticket Link

https://r161038.atlassian.net/browse/CSE-64

Issue Description

3

I am trying to create a wiki page using redmine rest api. The Authentication was succeeded, however the wiki page is not being created because of a 422 error.

The Redmine documentation says: "When trying to create or update an object with invalid or missing attribute parameters, you will get a 422 Unprocessable Entity response. That means that the object could not be created or updated."

But I can seem to find out where I have mess up. The PROBLEM CAME UP WHEN I DID THE SECOND REQUEST- "PUT REQUEST".

so we know the problem is somewhere in that section.

My guess is, it is either the file path or the content-type.

This is what I have so far....

{noformat}const wordDocument="C:\Users\adasani\Desktop\practice\RedmineApi/RedmineText.txt";

creatingWikiPage_Request(wordDocument);

function creatingWikiPage_Request(wordDocument) {

axios({
    method: 'post',
    url: '<redmine_url>/uploads.json',
    headers: { 'Content-Type': 'application/octet-stream' },
    params: { 'key': '<api-key>' },
    data: wordDocument
})
    .then(function (response) {
        console.log("succeeed--->  ");
        console.log(response.data.upload.token)
        axios({
            method: 'put',
            url: '<redmine_url>/projects/Testing/wiki/WikiTesting.json',
            headers: { 'Content-Type': 'application/octet-stream' },
            params: { 'key': '<api-key>' },
            data: {

                "wiki_page": {
                    "text": "This is a wiki page with images, and other files.",
                    "uploads":[ 
                        { "token": response.data.upload.token, "filename": "RedmineText.txt", "content-type": "text/plain" }
                    ]
                }

            }

        })
            .then(response => {
                console.log("PUT is Succeed-->>>")
                console.log(response)
            })
            .catch(error => {
                console.log("Error-->>")
                console.log(error.response)
            })

    })
    .catch(function (error) {
        console.log("failed----->  ");
        console.log(error.response.statusText, "-->", error.response.status);
        console.log(error.response.headers)
        console.log(error.message)
        console.log("failed----->  ");
    })

}

{noformat}

I am suppose to see a wiki page being created in my redmine dashboard but I am getting a 422 error.

What did we understand from the customer issue?

...

What doubts do we have?

...

Clarifications needed from the customer

...

Insights:

...

Supporting Internal Logs/Metrics

...

Approach/Next Steps

...

Environment

...

Checklist