Edits history of script submission #22608 for ' Update User (okta)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Update User
     * Partially update a user's profile and/or credentials. Only the fields you pass are changed (the rest are left intact). Pass `profile` as a map of profile attributes to set, and/or `credentials` (e.g. { password: { value } }).
     */
    export async function main(
      auth: RT.Okta,
      user_id: string,
      profile: { [key: string]: any } | undefined,
      credentials: { [key: string]: any } | undefined
    ) {
      const url = new URL(
        `${auth.org_url}/api/v1/users/${encodeURIComponent(user_id)}`
      )
    
      const body: { [key: string]: any } = {}
      if (profile !== undefined) body.profile = profile
      if (credentials !== undefined) body.credentials = credentials
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: `SSWS ${auth.token}`,
          "Content-Type": "application/json",
          Accept: "application/json",
        },
        body: JSON.stringify(body),
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 5 days ago