Jump to content

API Question...?


mnicholson

Recommended Posts

Hi

 

I have used the getuser part of the API a few times to obtain such things as a logged in user's username etc.

I am wondering - is it possible to use the API to obtain the names/id's of the children of a parent when they are logged in?

any help much appreciated!

Link to comment
Share on other sites

17 hours ago, mnicholson said:

Hi

 

I have used the getuser part of the API a few times to obtain such things as a logged in user's username etc.

I am wondering - is it possible to use the API to obtain the names/id's of the children of a parent when they are logged in?

any help much appreciated!

Certainly:

fdp/2/user/getChildren

That should do the trick. I don't think you need to pass any params as it will use the logged in users credentials.

Link to comment
Share on other sites

34 minutes ago, mnicholson said:

thanks - but I might need some more help with this!

what i need is a list of the children of that parent.  How can I use that code for this?  Can you point me to any example code?

thanks

Yes you can use the same API - all you need to do is send another param along with it that identifies the parent user: 'uuid'

e.g. (untested but should be something like the below)

var parent_users_uuid = "[some uuid goes here]";

var request_data = {
    url: 'user/getChildren',
    path: '../api/fdp/2/',
    dataType: 'json user',
    converters: {
        'json user': function(data) {
            return data.response;
        }.bind(this)
    },
    data: {
        'user' : parent_users_uuid
    }
}


Frog.Model.fdpapi(request_data).done(function(response_data){
    // response_data should contain the children of that user
}.bind(this)).error(function(err){
    //error handling here
});

 

Note that you can only get the data for other users children if you have the correct role in Frog. Admins will probably already have this role by default, other users won't. If you want staff to use this widget then you'll have to find and activate the 'Get user data for all users' role which is in:

Groups and policies -> [some group] -> Frog Developer Platform -> Users -> Get user data for all users.

Hope that helps.

Link to comment
Share on other sites

thanks - I had created my own bit of code (see below)...

 

the issue im having is once i have the child's data in the array I need to draw out the username of said child, thats the error im getting...any help?

<script>
var target = ""; 
FrogOS.fdp({
    path: Frog.Utilities.getBaseUrl() +'/api/2/',
    url: '',
    data: { method: 'users.getChildren' }
}).done(function(response) {
    if (response.status.message == 'OK' && response.data.length > 0) {
        //found some children, let's log them:
        console.log(response.data);
        //var target = users.getChildren(username);
        var user = FrogOS.users.getChildren().username;
        document.getElementById("demo").innerHTML = user;
    }
    else {
        var target = "no children found";
        //no children attached to this account or some kind of error, do something?
    }
});
document.getElementById("demo").innerHTML = target;   
</script>

 

Link to comment
Share on other sites

The console prints the following data out:

 

profile: Object { name: "Student", uuid: "F26B467820013B45967A2FDDFEB3BA0367F743EC8B388A5E" }

pupil_number: "W807233603064"
remote: false
remote_read_only: false
reset_password: false
reset_password_read_only: false
source: "misextractor"
updated: 1548123590
username: "12yatesb"
username_read_only: false
uuid: "255466BF20005DEE5E3B6FD651C0190E8924419C5CC588D8"

What do I have to do to reference just the 'username' part as thats what i need to write into a variable

Link to comment
Share on other sites

3 hours ago, mnicholson said:

thanks - I had created my own bit of code (see below)...

 

the issue im having is once i have the child's data in the array I need to draw out the username of said child, thats the error im getting...any help?


<script>
var target = ""; 
FrogOS.fdp({
    path: Frog.Utilities.getBaseUrl() +'/api/2/',
    url: '',
    data: { method: 'users.getChildren' }
}).done(function(response) {
    if (response.status.message == 'OK' && response.data.length > 0) {
        //found some children, let's log them:
        console.log(response.data);
        //var target = users.getChildren(username);
        var user = FrogOS.users.getChildren().username;
        document.getElementById("demo").innerHTML = user;
    }
    else {
        var target = "no children found";
        //no children attached to this account or some kind of error, do something?
    }
});
document.getElementById("demo").innerHTML = target;   
</script>

 

Try something like this:

FrogOS.fdp({
    path: Frog.Utilities.getBaseUrl() +'/api/2/',
    url: '',
    data: { method: 'users.getChildren' }
}.bind(this).done(function(response) {
  	var count = response.data.length;
  	if (count == 0) {
    	//handle no results here - for example a 'no children found' message
    }
  	//loop over all returned children here:
  	for (var i = 0; i < response.data.length; i++) {
    	var user = response.data[i];
      //you can then use it like this:
      // var display_name = user.display_name;
      // var username = user.username;
      // etc...	
    }
}.bind(this));

 

Link to comment
Share on other sites

i have put that in (see below) but keep getting a malformed javascript error!

 

FrogOS.fdp({
    path: Frog.Utilities.getBaseUrl() +'/api/2/',
    url: '',
    data: { method: 'users.getChildren' }
}.bind(this).done(function(response) {
  	var count = response.data.length;
  	if (count == 0) {
    	var result = "no children found";
      //handle no results here - for example a 'no children found' message
    }
  	//loop over all returned children here:
  	for (var i = 0; i < response.data.length; i++) {
    	var user = response.data[i];
      //you can then use it like this:
      // var display_name = user.display_name;
      var result = user.username;
      // etc...	
    }
}.bind(this));

thanks for the help so far by the way!

Link to comment
Share on other sites

Just a couple of brackets in the wrong place:

FrogOS.fdp({
    path: Frog.Utilities.getBaseUrl() +'/api/2/',
    url: '',
    data: { 
      method: 'users.getChildren' 
    }
}).done(function(response) {
  	var count = response.data.length;
  	if (count == 0) {
    	var result = "no children found";
    }
  	//loop over all returned children here:
  	for (var i = 0; i < response.data.length; i++) {
    	var user = response.data[i];
      var result = user.username;
    }
  }.bind(this));

 

  • Thanks 1
Link to comment
Share on other sites

Yeah I tried a few brackets but god knows i hate finding syntax errors! (didn't have access to dreamweaver etc. today to some any diagnostics).

anyway the code works brilliantly - so thanks so much for your help!  No doubt Ill be asked to use it for a variety of things now haha..meaning more work!

 

thanks again!

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...