Amplify-js: What's the correct format of data to use for setting Cognito User `address`?

Created on 12 Feb 2019  路  3Comments  路  Source: aws-amplify/amplify-js

* Which Category is your question related to? *
Cognito User Attribute Management

* What AWS Services are you utilizing? *
Cognito

* Provide additional details e.g. code snippets *
What format of data should be submitted when setting a user's address attribute? When I submit an object to Auth.updateUserAttributes I can only get it to succeed if I pass in a string. Is it expected that we submit JSON?

I haven't been able to find any documentation regarding this attribute.

const user = await Auth.currentAuthenticatedUser()

const address = {
  locality: "New York"
  postal_code: "10002"
  region: "New York"
  street_address: "138 E Broadway"
}

const result = await Auth.updateUserAttributes(user, {
  // address // errors
  address: JSON.stringify(address) // succeeds
})

The error I get when submitting an object is:

code: "SerializationException"
message: "Start of structure or map found where not expected."
name: "SerializationException"
Cognito question

Most helpful comment

Hi @lsirivong

What format of data should be submitted when setting a user's address attribute? When I submit an object to Auth.updateUserAttributes I can only get it to succeed if I pass in a string. Is it expected that we submit JSON?

address is one of cognito's standard attributes, which are implemented following the OpenID Connect specification. Per the spec, it is a JSON string:

address | JSON object | End-User's preferred postal address. The value of the聽address聽member is a JSON聽[RFC4627]聽structure containing some or all of the members defined in聽Section聽5.1.1.
-- | -- | --

I just tried copy-pasting your code as-is in a test app and the attribute was successfully updated. I am not sure what could be wrong. Do you have a more detailed stack trace?

All 3 comments

Hi @lsirivong

What format of data should be submitted when setting a user's address attribute? When I submit an object to Auth.updateUserAttributes I can only get it to succeed if I pass in a string. Is it expected that we submit JSON?

address is one of cognito's standard attributes, which are implemented following the OpenID Connect specification. Per the spec, it is a JSON string:

address | JSON object | End-User's preferred postal address. The value of the聽address聽member is a JSON聽[RFC4627]聽structure containing some or all of the members defined in聽Section聽5.1.1.
-- | -- | --

I just tried copy-pasting your code as-is in a test app and the attribute was successfully updated. I am not sure what could be wrong. Do you have a more detailed stack trace?

I must have overlooked that the specification said JSON object. I was expecting the API to expect an actual object.

Thanks for confirming that it should be JSON.

What is a JSON object? That sounds like bad documentation imo.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shinnapatthesix picture shinnapatthesix  路  3Comments

guanzo picture guanzo  路  3Comments

rayhaanq picture rayhaanq  路  3Comments

ddemoll picture ddemoll  路  3Comments

romainquellec picture romainquellec  路  3Comments