-2

Here is my code:

axios({
  method: "GET",
  url: "http://112.196.108.244:9002/api/survey/question/get-question/not-answered/?surveyId=",
  headers: {
    "content-type": "application/json",
    Authorization: `Bearer token-key`,
  },
  body: {
    id: "68367859",
    isMandatory: "false",
    paginationFilter: { limit: 10, offset: 0, order: "DESC" },
    filterInput: {
      locationIds: ["1", "4011403", "4012144"],
      categoryIds: [
        "twoSubCategories/7898496",
        "domains/7895290",
        "subCategories/7896491",
      ],
    },
  },
})
  .then((response) => {
    console.log("response", response);
  })
  .catch((error) => {
    console.log("error", error.response.data);
  });

this code gives me error: The error in console is-

details: "uri=/api/survey/question/get-question/not-answered/"
message: "document key  is not valid."
status: 400
Phil
  • 157,677
  • 23
  • 242
  • 245
  • The Axios option you want is `data`, not `body`. See https://github.com/axios/axios#request-config. There's also no need to set the content-type header – Phil Jan 10 '23 at 06:02
  • I fixed the formatting in your question but were you not shown a preview of how it would look before you posted it? – Phil Jan 10 '23 at 06:05
  • @Phil I replace body with data, but still the same error comes. – Garima Garg Jan 10 '23 at 06:06
  • The code in your question doesn't look any different. Please [edit] it to match what you're currently using. Also, what request payload does the API expect? Do you have any documentation you can reference? – Phil Jan 10 '23 at 06:07

1 Answers1

0

You're passing the id in the body. There are two problems at play here:

  1. GET requests shouldn't use a body as part of the request. Check this answer.
  2. What you want to do is pass the id (Which I assume is the survey id) as a query parameter. Something like this should work:
        axios({
        method: 'GET',
        url: 'http://112.196.108.244:9002/api/survey/question/get-question/not-answered/',
        headers: {
            'content-type': 'application/json',
            Authorization: "Bearer token-key"
        },
        params: {
            surveyId: "68367859"
        }
    })

Add other params as necessary.

Luciano
  • 354
  • 1
  • 7