'ManageEngine servicedesk plus REST API POST with REACT

I am working to create a connection of a REST API to my REACT Web APP.

The API is a ready API of ManageEngine Service Desk Plus which works in POSTMAN and also using Python requests library but fails when done with axios and do not understand that so if anybody could help in implementation.

ServiceDesk is hosted on server too.

Axios Code(Which Does not work and Proxy setup has been done and also tried multiple variants using qs.stringfy() UrlSearchParams() none worked and return with 500 errror):

import axios from "axios";

const Post = () => {
  const url = "api/v3/requests";
  const headers = {
    authtoken: "170AFE36-22B3-4485-96B1-57766CE067A4",
    "content-type": "application/json",
  };
  const input_data = {
    request: {
      subject: "Unable to fetch mails",
      description: "I am unable to fetch mails from the mail server",
      requester: {
        email_id: "[email protected]",
        name: "bank",
        is_vipuser: false,
        id: "619",
      },
      udf_fields: {
        udf_sline_3358: "Morogoro",
        udf_sline_3368: null,
        udf_sline_3366: "6626 SS S1 LONG",
        udf_sline_3359: "ATM 132",
        udf_pick_3364: "BREAK DOWN",
        udf_pick_3367: "Branch",
        udf_date_3375: null,
        udf_date_3374: null,
        udf_date_3373: null,
        udf_pick_3363: "1",
        udf_sline_3360: "Asifiwnme",
        udf_sline_3365: "Hamis Sheghembe",
        udf_sline_3362: "83-41103176",
      },
      resolution: {
        content: "Mail Fetching Server problem has been fixed",
      },
      status: {
        name: "Open",
      },
    },
  };
  const data = {
    input_data: input_data,
  };
  axios
    .post(url, data, {
      headers: headers,
    })
    .then((response) => {
      console.log(response);
    })
    .catch((error) => {
      console.log(error);
    });

  return <div></div>;
};

export default Post;

Postman Snapshot That works:

Postman Working Snapshot

And a python code which works too here:

Py code snap

I need an idea that how to consume this REST api in my app help me out.



Solution 1:[1]

Okay so I figured out partially for now Thanks to POSTMAN request providing a code for helping me out where they had a sample request and using it got a solution.

More related to the pathetic coders or documentation makers for messing with the formatting of how response should go.

Documentation says send data as json however in reality data has to be sent in x-www-url-encoded format

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 alphabugsme