How to update profile information via API


(Kenny Meyer) #1

I would like to sync profile information like the bio, and website URL from my website to the discourse user forum. Users are currently all logging in via an SSO endpoint on the main website. Is there any way to update the discourse user profile via an API call?

I have tried doing something like this, unsuccessfully:

require 'single_sign_on'
class DiscourseSsoController < ApplicationController
  before_filter :authenticate_user! # ensures user must login

  def sso
    secret = ENV["DISCUSSIONS_SSO_KEY"]
    sso = SingleSignOn.parse(request.query_string, secret)
    sso.email = current_user.email # from devise
    sso.name = current_user.name # this is a custom method on the User class
    sso.username = current_user.name # from devise
    sso.external_id = current_user.id # from devise
    sso.sso_secret = secret
    sso.avatar_url = current_user.image_url
    sso.bio = current_user.bio
    sso.custom_fields["profile_url"] = SOME_URL

    redirect_to sso.to_url(ENV["DISCUSSIONS_SSO_LOGIN_PATH"])
  end
end

(Kenny Meyer) #2

No help? I wonder if my question is clear enough…


(Christopher Heald) #3

Using the API:

curl -X PUT -d 'name=BOB TEST' http://your.discourse.instance/users/<DISCOURSE_USERNAME>.json?api_key=<API_KEY>&api_username=<API_USER>

Take a look at the Discourse API.