Hi been at this all night, now time to ask the wise!
What is wrong with this?!
I have set privileges to everything for POST GETS, API and SCRIPTS. The idea is to add some data to an external database when a user registers. The JSON works in the API docs (so the fields are right) but not as a pre or post POST. hiyer is the MySQL service name and the registration in the DF Users section are being added fine for both pre and post post.
That looks about right. Have you done a var_dump or some such thing just to see if the script is actually executing?
Sridhar
Yes it does…I get this
[2016-04-23 19:14:17] local.DEBUG: Resource event: user.register.post.pre_process
[2016-04-23 19:14:17] local.DEBUG: Resource event: user.register.post.post_process
[2016-04-23 19:14:18] local.DEBUG: Resource event: Hiyer._table.{table_name}.post.pre_process
[2016-04-23 19:14:18] local.DEBUG: Resource event: Hiyer._table.Users.post.pre_process
[2016-04-23 19:14:18] local.DEBUG: Resource event: Hiyer._table.Users.post.post_process
[2016-04-23 19:14:18] local.DEBUG: Resource event: Hiyer._table.{table_name}.post.post_process
[2016-04-23 19:14:18] local.INFO: * Script “user.register.post.post_process” output:
object(Object)#1176534077 (1) {
[“success”] =>
bool(true)
}
object(Object)#591631922 (5) {
[“email”] =>
string(15) "max4@tester.com"
[“first_name”] =>
string(3) “Max”
[“last_name”] =>
string(6) “Thomas”
[“display_name”] =>
string(4) “Mr T”
[“new_password”] =>
string(6) “123456”
}
NULL
I used this in the script for logging
var_dump(event.response.content);
var_dump(event.request.payload);
var_dump(event.request.payload.resource);
Is the payload as we would expect…for instance I do not have a a field in the database for display_name but I did not think I was asking for one.Now I look at the script, how does DF know which fields to map to the db?
OK finally worked it out to be about roles. The problem is that there is a bug and although I got it working by adding a role to the Admin service, shortly afterwards it stopped working. Not thinking it was a bug I spent another 5 hours on it until I deleted a role. But I did this before taking the role off the APP and the whole system died with a big red API error can´t find role (could not add another one, delete the old ones, reassign a new role to the app). So I create a new Amazon instance and started from scratch. It was v 2.2.1-5 and it worked with the same script first time both in API docs and externally with Google REST console once the roles had been added.
Here is the script which uses system variables so the internal DB is a reflection of the external one. The only thing is that user.id comes in NULL and I am wondering if that is another bug. It is not the only way of connecting the 2 databases, user.email will work too, but it being an integer it is the best one. Anyone know how to get the user.id system variable to work?
var user_data;
var user = event.request.payload;
user_data ={‘resource’: [ { ‘DFUserID’ : user.id,‘FirstName’: user.first_name, ‘LastName’: user.last_name, ‘Email’:user.email, ‘KnownAs’: user.display_name } ] };
var send = platform.api.post(“hiyerDB/_table/Users?fields=FirstName,LastName”, user_data);
BTW the fields= parameters have no bearing on whether this code works, it simply defines what you get in response. Took me a while to work that out too.