0

I'm having problems trying to use a POST request in axios. I need to send an object to my backend, but it receives predefined values ​​inside my function, so I can't send all my data. I tried in different ways and got different messages but I still couldn't find my error.

export function createUsers(user: userApi) {
  user.pin = '001'
  user.customFields = []  
  //@ts-ignore
  user.admission_at = selectedDate.value

  return axios.post('/users',{
    ...user,
    admission_at: dateBr(user.admission_at)
  })
}

In this first attempt when I send data, it ends up sending only the pre-defined values:

enter image description here

On the second try I only modified my return, but this time I send my object and it ignored my predefined values, like the "pin" for example. That way I didn't know how to format my date either, using "dateBr". I believe that the best way to send is the first one, but I need all the data

enter image description here

export function createUsers(user: userApi) {
  user.pin = '001'
  user.customFields = []  
  //@ts-ignore
  user.admission_at = selectedDate.value
    
 return axios.post('/users', user)
}
export interface userApi extends Record<string, unknown>{
  customFields?: string[]; 
  company?: number|string;
  email: string;
  password: string;
  name: string;
  admission_at: string;
  cpf: string;
  profession: string;
  phone: string;
  pin?: string;
  enrollment: string;
  department_id: string;
}
Mark
  • 51
  • 1
  • 6
  • Please, provide https://stackoverflow.com/help/mcve for your problem. It's unknown why you expect it to behave differently. Notice that the requests are of different types. If you try to modify `FormData` object the same way as plain object, it obviously won't work – Estus Flask Apr 25 '22 at 14:30
  • 1
    Possible duplicate of https://stackoverflow.com/questions/23118249/whats-the-difference-between-request-payload-vs-form-data-as-seen-in-chrome – Estus Flask Apr 25 '22 at 14:33

0 Answers0