# Problem with post data to API with JS/React

**URL:** <https://community.auth0.com/t/problem-with-post-data-to-api-with-js-react/71268>\
**Category:** Get Help\
**Created:** [October 13, 2021, 7:14pm UTC](https://community.auth0.com/t/problem-with-post-data-to-api-with-js-react/71268 "2021-10-13T19:14:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![adriann.kowalski](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/adriann.kowalski/32/24847_2.png) [@adriann.kowalski](https://community.auth0.com/u/adriann.kowalski)\
**Post date:** [October 13, 2021, 7:14pm UTC](https://community.auth0.com/t/problem-with-post-data-to-api-with-js-react/71268/1 "2021-10-13T19:14:29Z")

</div>

Hello

I try to make post call to api to update user information but im getting error:

1. error: “Bad Request”
2. errorCode: “invalid\_body”
3. message: “Payload validation error: ‘Expected type object but found type string’.”
4. statusCode: 400

Here’s my update function →

const postUserMetadata = async () =\> {

```
      try {

        const accessToken = await getAccessTokenSilently({

          audience: `https://${domain}/api/v2/`,

          scope: "update:users",

        });

        const userDetailsByIdUrl = `https://${domain}/api/v2/users/${user.sub}`;

       const metadataResponse = await fetch(userDetailsByIdUrl, {

          body:{

```

“user\_metadata”: {  
“addresses”: {  
“work\_address”: “100 Industrial Way”,  
“home\_address”: “742 Evergreen Terrace”  
}  
}  
},

```
          headers: {

            Authorization: `Bearer ${accessToken}`,

          },

          method: 'PATCH',

        });

        const { user_metadata } = await metadataResponse.json();
      } catch (e) {

        console.log(e.message);

      }

    };

```

I’ve tried to add “Content-Type”: “application/json”

to header but then i got different error  
“Invalid request payload JSON format”

when i store data which i want to send to api to variable as a object and check its type it’s clearly  
says that’s object so what’s wrong ?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [October 13, 2021, 8:05pm UTC](https://community.auth0.com/t/problem-with-post-data-to-api-with-js-react/71268/3 "2021-10-13T20:05:44Z")

</div>

Hi @adriann.kowalski,

Welcome to the Auth0 Community!

I understand that you are having problems with your PATCH request to the Management API `/api/v2/users/` endpoint, specifically with the `"Payload validation error: 'Expected type object but found type string'."` error.

This error normally occurs when the payload’s Content-Type is in plain text, therefore returning the content as a string rather than a JSON object as expected.

After looking closely at your code snippet, I noticed that you need to specify the `Content-Type` header. Could you please include the following:

```auto
headers: {

Authorization: 'Bearer ${accessToken}',
Content-Type: 'application/json',

},

```

EDIT: If you encounter the `“Invalid request payload JSON format”` error after making these changes, please double check that your request is indeed in the correct format.

Please let me know whether this resolves your issue.

Thank you.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [December 6, 2021, 11:03pm UTC](https://community.auth0.com/t/problem-with-post-data-to-api-with-js-react/71268/4 "2021-12-06T23:03:24Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
