SivaDev1038 / testing-jira-github

0 stars 0 forks source link

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

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. SmartAttachmentBean{source=AttachmentBean{self='https://r161038.atlassian.net/rest/api/2/attachment/10006', id=10006, filename='2n504failedPath.csv', author=UserBean{name='null', key='null', accountId='636b7e34d60bd2b365f8c8e6', emailAddress='null', displayName='r161038', active=true, timeZone='Asia/Calcutta', locale='null'}, created=Wed Jan 25 09:11:20 UTC 2023, size=16351, mimeType='text/plain', content='https://r161038.atlassian.net/rest/api/2/attachment/content/10006'}} AttachmentBean{self='https://r161038.atlassian.net/rest/api/2/attachment/10006', id=10006, filename='2n504failedPath.csv', author=UserBean{name='null', key='null', accountId='636b7e34d60bd2b365f8c8e6', emailAddress='null', displayName='r161038', active=true, timeZone='Asia/Calcutta', locale='null'}, created=Wed Jan 25 09:11:20 UTC 2023, size=16351, mimeType='text/plain', content='https://r161038.atlassian.net/rest/api/2/attachment/content/10006'}, SmartAttachmentBean{source=AttachmentBean{self='https://r161038.atlassian.net/rest/api/2/attachment/10009', id=10009, filename='2n504failedPath.txt', author=UserBean{name='null', key='null', accountId='636b7e34d60bd2b365f8c8e6', emailAddress='null', displayName='r161038', active=true, timeZone='Asia/Calcutta', locale='null'}, created=Wed Jan 25 09:11:20 UTC 2023, size=36570, mimeType='application/json', content='https://r161038.atlassian.net/rest/api/2/attachment/content/10009'}} AttachmentBean{self='https://r161038.atlassian.net/rest/api/2/attachment/10009', id=10009, filename='2n504failedPath.txt', author=UserBean{name='null', key='null', accountId='636b7e34d60bd2b365f8c8e6', emailAddress='null', displayName='r161038', active=true, timeZone='Asia/Calcutta', locale='null'}, created=Wed Jan 25 09:11:20 UTC 2023, size=36570, mimeType='application/json', content='https://r161038.atlassian.net/rest/api/2/attachment/content/10009'}, SmartAttachmentBean{source=AttachmentBean{self='https://r161038.atlassian.net/rest/api/2/attachment/10010', id=10010, filename='2n504failedPath1.txt', author=UserBean{name='null', key='null', accountId='636b7e34d60bd2b365f8c8e6', emailAddress='null', displayName='r161038', active=true, timeZone='Asia/Calcutta', locale='null'}, created=Wed Jan 25 09:11:21 UTC 2023, size=33280, mimeType='application/json', content='https://r161038.atlassian.net/rest/api/2/attachment/content/10010'}} AttachmentBean{self='https://r161038.atlassian.net/rest/api/2/attachment/10010', id=10010, filename='2n504failedPath1.txt', author=UserBean{name='null', key='null', accountId='636b7e34d60bd2b365f8c8e6', emailAddress='null', displayName='r161038', active=true, timeZone='Asia/Calcutta', locale='null'}, created=Wed Jan 25 09:11:21 UTC 2023, size=33280, mimeType='application/json', content='https://r161038.atlassian.net/rest/api/2/attachment/content/10010'}, SmartAttachmentBean{source=AttachmentBean{self='https://r161038.atlassian.net/rest/api/2/attachment/10007', id=10007, filename='ChatGPT.pdf', author=UserBean{name='null', key='null', accountId='636b7e34d60bd2b365f8c8e6', emailAddress='null', displayName='r161038', active=true, timeZone='Asia/Calcutta', locale='null'}, created=Wed Jan 25 09:11:20 UTC 2023, size=67277, mimeType='application/pdf', content='https://r161038.atlassian.net/rest/api/2/attachment/content/10007'}} AttachmentBean{self='https://r161038.atlassian.net/rest/api/2/attachment/10007', id=10007, filename='ChatGPT.pdf', author=UserBean{name='null', key='null', accountId='636b7e34d60bd2b365f8c8e6', emailAddress='null', displayName='r161038', active=true, timeZone='Asia/Calcutta', locale='null'}, created=Wed Jan 25 09:11:20 UTC 2023, size=67277, mimeType='application/pdf', content='https://r161038.atlassian.net/rest/api/2/attachment/content/10007'}, SmartAttachmentBean{source=AttachmentBean{self='https://r161038.atlassian.net/rest/api/2/attachment/10005', id=10005, filename='ChatGPT2.pdf', author=UserBean{name='null', key='null', accountId='636b7e34d60bd2b365f8c8e6', emailAddress='null', displayName='r161038', active=true, timeZone='Asia/Calcutta', locale='null'}, created=Wed Jan 25 09:11:19 UTC 2023, size=52819, mimeType='application/pdf', content='https://r161038.atlassian.net/rest/api/2/attachment/content/10005'}} AttachmentBean{self='https://r161038.atlassian.net/rest/api/2/attachment/10005', id=10005, filename='ChatGPT2.pdf', author=UserBean{name='null', key='null', accountId='636b7e34d60bd2b365f8c8e6', emailAddress='null', displayName='r161038', active=true, timeZone='Asia/Calcutta', locale='null'}, created=Wed Jan 25 09:11:19 UTC 2023, size=52819, mimeType='application/pdf', content='https://r161038.atlassian.net/rest/api/2/attachment/content/10005'}, SmartAttachmentBean{source=AttachmentBean{self='https://r161038.atlassian.net/rest/api/2/attachment/10008', id=10008, filename='command-address.txt', author=UserBean{name='null', key='null', accountId='636b7e34d60bd2b365f8c8e6', emailAddress='null', displayName='r161038', active=true, timeZone='Asia/Calcutta', locale='null'}, created=Wed Jan 25 09:11:20 UTC 2023, size=68, mimeType='text/plain', content='https://r161038.atlassian.net/rest/api/2/attachment/content/10008'}} AttachmentBean{self='https://r161038.atlassian.net/rest/api/2/attachment/10008', id=10008, filename='command-address.txt', author=UserBean{name='null', key='null', accountId='636b7e34d60bd2b365f8c8e6', emailAddress='null', displayName='r161038', active=true, timeZone='Asia/Calcutta', locale='null'}, created=Wed Jan 25 09:11:20 UTC 2023, size=68, mimeType='text/plain', content='https://r161038.atlassian.net/rest/api/2/attachment/content/10008'}

What did we understand from the customer issue?

...

What doubts do we have?

...

Clarifications needed from the customer

...

Insights:

...

Supporting Internal Logs/Metrics

6 attachments are there in the issue please paste those attachments here

Approach/Next Steps

...

Environment

...

Checklist