Hey guys, I'm extremely new to Ory, but I was wond...
# talk-kratos
n
Hey guys, I'm extremely new to Ory, but I was wondering if I could get some help trouble shooting an error. I'm going to try my best to articulate what's going on, so please let me know if I didn't provide enough context or the question is asked in a poor way. I have a tool that will allow me to perform some admin operations onto users who have authenticated with Kratos. I'm able to get people's identities by calling the node SDK like so:
Copy code
const get = id => sdk.getIdentity({ id });
In addition, I'm able to list things out by calling:
Copy code
const list = makePaging(page => sdk.listIdentitiesRaw({ page }));
The problem is when I want to update anything in a user's identity. Here's my function:
Copy code
const updateUsername = async (id, username) => {
    const adminUpdateIdentityBody = { traits: { username } };
    const current = await get(id);
    if ('traits' in adminUpdateIdentityBody) {
      adminUpdateIdentityBody.traits = { ...current.traits, ...adminUpdateIdentityBody.traits };
    }
    return sdk.updateIdentity({ id, adminUpdateIdentityBody }).catch(err => err.response.json());
  };
Here's sample local data from a fake user:
Copy code
{
  created_at: 2022-12-09T02:11:50.965Z,
  credentials: {
    oidc: {
      config: undefined,
      created_at: 2022-12-09T02:11:50.980Z,
      identifiers: [Array],
      type: 'oidc',
      updated_at: 2022-12-09T02:11:50.980Z,
      version: 0
    },
    password: {
      config: undefined,
      created_at: 2022-12-09T02:11:51.009Z,
      identifiers: [Array],
      type: 'password',
      updated_at: 2022-12-09T02:11:51.009Z,
      version: 0
    }
  },
  id: 'fake-uuid',
  metadata_admin: undefined,
  metadata_public: undefined,
  recovery_addresses: undefined,
  schema_id: 'user-v1',
  schema_url: 'some-kratos-schema-url',
  state: 'active',
  state_changed_at: 2022-12-09T02:11:50.963Z,
  traits: {
    secondaryEmails: [ '<mailto:fake4@gmail.com|fake4@gmail.com>' ],
    tos: true,
    username: 'fake'
  },
  updated_at: 2022-12-09T02:11:50.965Z,
  verifiable_addresses: undefined
here's what I get when i try to change the username via
Copy code
auth.updateUsername( '3a732e1a-9f8d-4006-bd8b-5d9e82f5616a', 'fakeee')
result:
Copy code
{
  error: {
    code: 400,
    status: 'Bad Request',
    reason: 'Unable to decode HTTP Request Body because its HTTP Header "Content-Length" is zero.',
    message: 'The request was malformed or contained invalid parameters'
  }
}
m
Hmm how are you sending the request @narrow-dusk-31843? Might be something strips the header? Are you hosting Kratos yourself or using Ory Network? And what version SDK are you on?
n
self hosted! 0.11.0 kratos, and 0.40.0 for oathkeeper
this is how im calling the request:
sdk.updateIdentity({ id, adminUpdateIdentityBody }).catch(err => err.response.json());