Need help with user.register.post.post_process script


#1

Hi,

I’m trying to get an email sent to the user after registration. (Using Open Registration without confirmation). Using DF 2.0 in AWS by Bitnami.

So I created a script in user.register.post.post_process. (V8js)

var_dump(event.request); // outputs to file in storage/log of dreamfactory install directory
var lodash = require("lodash.min.js");

if (event.request.payload.resource) {
    lodash._.each (event.request.payload.resource, function( record ) {
	var payload = {
  "template": "User Registration Default",
  "template_id": null,
  "to": [
    {
      "name": "Allen Sandiego",
      "email": "email@domain.com"
    }
  ],
  "cc": [
    {
      "name": "",
      "email": ""
    }
  ],
  "bcc": [
    {
      "name": "",
      "email": ""
    }
  ],
  "subject": "Test",
  "body_text": "Test",
  "body_html": "",
  "from_name": "Admin",
  "from_email": "admin@domain.com",
  "reply_to_name": "",
  "reply_to_email": ""
}
	platform.api.post('email', JSON.stringify(payload));

    });
}`

However, I’m not receiving any email. Where do I check the logs to get more information?

Thanks,
Allen


#2

If you put just those fields in payload, the email will be sent.

{
  "template": "My Template Name",
  "to": [
    {
      "name": params.name,
      "email": params.email
    }
  ]
}

because all other information will be in template, like subject, body_text, from, etc.

And I don’t think you need to put JSON.stringify on the payload param(perhaps this is the problem).


#3

Hi,

Thanks for the response.

I tried your suggestion. It works when directly calling the email api using Google Chrome’s Advance Rest Client. I receive the email this way.

However, when I call the user/register api from Google Chrome’s Advance Rest Client, I still don’t receive the email.

This is what I have now.

var_dump(event.request); // outputs to file in storage/log of dreamfactory install directory

var lodash = require("lodash.min.js");

if (event.request.payload.resource) {

    lodash._.each (event.request.payload.resource, function( record ) {

	var payload = {
  "template": "User Registration Default",
  "to": [
    {
      "name": "Allen Sandiego",
      "email": "email@domain.com"
    }
  ],
  "from_name": "Admin",
  "from_email": "admin@domain.com"
}
	platform.api.post('email', payload);

    });
}

Unfortunately I think there’s still something wrong with it as I still don’t get any email whenever I register.

Regards,
Allen


#4

Check if you have in your email role, the permission to requestor access via Script, not only API.


#5

Hi,

Yes I have setup the email in my role’s access. I have also set my CORS to use * just in case. But still no luck.

Something I noticed though when using Google Chrome’s Advance Rest Client. When I supply the X-DreamFactory-Session-Token, I get “Access Forbidden”. But when I remove this and use X-DreamFactory-API-Key instead, it works.

Do I need to supply the API Key in the event script? If so, how do I do this?

Thanks,
Allen


#6

You are using DF 2, so you need to use X-DreamFactory-API-Key in your header, with the hash provided by dreamfactory in app tab.


#7

Hi,

Can you provide a sample code on how to include the API Key in the event script? I’m not quite familiar with JS.

Thanks.


#8

In the event script you don’t need it. Just in Chrome Rest Client.


#9

Ok. But I’m still having a problem in the event script as it is not sending any email whenever a user registers.

Is there anyway to get any log messages so I can check if there are any errors. I have no problems using Chrome’s Rest Client.

Thanks.


#10

Alright, just one last thing: have you tried to put just this:

platform.api.post('email', {
"template": "My Template Name",
  "to": [
    {
      "name": "The Name",
      "email": "super@mail.com"
    }
  ]
});

in your script? remove all other code and see if it works after all?


#11

Ok. It seems to work this way.

Now I just need to get information of the user that registered so I can use them in the email.


#12

Great!!
Now you can pass parameters through the rest call.
Like this:

platform.api.post('email', {
"username": "The name",
"city":"Df Island",
"information":"more information",
"template": "My Template Name",
  "to": [
    {
      "name": "The Name",
      "email": "super@mail.com"
    }
  ]
});

and in the template email you use those variables like:

Hello {username} from {city},
here's your informations: {information}

#13

How do I reference the information of the record that currently registered.

Like name and email?


#14

You could get the user data:

user = event.request.body.record; (this is the body of the initial request, you have access to it)
var user_data = _.first(platform.api.get('my-db/users?fields=name,email,city,information', {
        filter: "email = " + user.email
    }).record);

then use it:

platform.api.post('email', {
"username": user_data.name,
"city": user_data.city,
"information": user_data.information,
"template": "My Template Name",
  "to": [
    {
      "name": user_data.name,
      "email": user_data.email
    }
  ]
});

#15

I tried this.

user = event.request.body.record;
var payload = {
  "to": [
    {
      "name": "Allen Sandiego",
      "email": "email@domain.com"
    }
  ],
  "subject": "Welcome",
  "body_html": "{name},<br/><br/>You have successfully registered!",
  "from_name": "Allen Sandiego",
  "from_email": "email@domain.com",
  "name": user.email
}
platform.api('email', payload);

However, I’m getting the following error:

{"error":{"context":null,"message":"Cannot read property 'record' of undefined","code":500,"trace":["0 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Handlers/Events/ServiceEventHandler.php(149): DreamFactory\\Core\\Handlers\\Events\\ServiceEventHandler->handleEventScript('user.register.p...', Array)","1 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Handlers/Events/ServiceEventHandler.php(102): DreamFactory\\Core\\Handlers\\Events\\ServiceEventHandler->onPostProcess('user.register.p...', Object(DreamFactory\\Core\\Events\\ResourcePostProcess))","2 [internal function]: DreamFactory\\Core\\Handlers\\Events\\ServiceEventHandler->onResourcePostProcess(Object(DreamFactory\\Core\\Events\\ResourcePostProcess))","3 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9772): call_user_func_array(Array, Array)","4 [internal function]: Illuminate\\Events\\Dispatcher->Illuminate\\Events\\{closure}(Object(DreamFactory\\Core\\Events\\ResourcePostProcess))","5 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9717): call_user_func_array(Object(Closure), Array)","6 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(6015): Illuminate\\Events\\Dispatcher->fire(Object(DreamFactory\\Core\\Events\\ResourcePostProcess))","7 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Resources/BaseRestResource.php(108): Illuminate\\Support\\Facades\\Facade::__callStatic('fire', Array)","8 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Resources/BaseRestResource.php(108): Illuminate\\Support\\Facades\\Event::fire(Object(DreamFactory\\Core\\Events\\ResourcePostProcess))","9 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Components/RestHandler.php(181): DreamFactory\\Core\\Resources\\BaseRestResource->postProcess()","10 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Components/RestHandler.php(224): DreamFactory\\Core\\Components\\RestHandler->handleRequest(Object(DreamFactory\\Core\\Utility\\ServiceRequest), '')","11 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Components/RestHandler.php(172): DreamFactory\\Core\\Components\\RestHandler->handleResource(Array)","12 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Services/BaseRestService.php(65): DreamFactory\\Core\\Components\\RestHandler->handleRequest(Object(DreamFactory\\Core\\Utility\\ServiceRequest), 'register')","13 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Utility/ServiceHandler.php(57): DreamFactory\\Core\\Services\\BaseRestService->handleRequest(Object(DreamFactory\\Core\\Utility\\ServiceRequest), 'register')","14 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17588): DreamFactory\\Core\\Utility\\ServiceHandler::processRequest('v2', 'user', 'register')","15 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17564): DreamFactory\\Http\\Controllers\\RestController->handleService('v2', 'user', 'register')","16 [internal function]: DreamFactory\\Http\\Controllers\\RestController->handlePOST('v2', 'user', 'register')","17 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8842): call_user_func_array(Array, Array)","18 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8911): Illuminate\\Routing\\Controller->callAction('handlePOST', Array)","19 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8891): Illuminate\\Routing\\ControllerDispatcher->call(Object(DreamFactory\\Http\\Controllers\\RestController), Object(Illuminate\\Routing\\Route), 'handlePOST')","20 [internal function]: Illuminate\\Routing\\ControllerDispatcher->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))","21 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9553): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))","22 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17850): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))","23 [internal function]: DreamFactory\\Http\\Middleware\\AccessCheck->handle(Object(Illuminate\\Http\\Request), Object(Closure))","24 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)","25 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))","26 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9535): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))","27 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8892): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))","28 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8877): Illuminate\\Routing\\ControllerDispatcher->callWithinStack(Object(DreamFactory\\Http\\Controllers\\RestController), Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request), 'handlePOST')","29 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7831): Illuminate\\Routing\\ControllerDispatcher->dispatch(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request), 'DreamFactory\\\\Ht...', 'handlePOST')","30 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7802): Illuminate\\Routing\\Route->runWithCustomDispatcher(Object(Illuminate\\Http\\Request))","31 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7455): Illuminate\\Routing\\Route->run(Object(Illuminate\\Http\\Request))","32 [internal function]: Illuminate\\Routing\\Router->Illuminate\\Routing\\{closure}(Object(Illuminate\\Http\\Request))","33 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9553): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))","34 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))","35 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9535): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))","36 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7456): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))","37 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7444): Illuminate\\Routing\\Router->runRouteWithinStack(Object(Illuminate\\Routing\\Route), Object(Illuminate\\Http\\Request))","38 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7429): Illuminate\\Routing\\Router->dispatchToRoute(Object(Illuminate\\Http\\Request))","39 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2304): Illuminate\\Routing\\Router->dispatch(Object(Illuminate\\Http\\Request))","40 [internal function]: Illuminate\\Foundation\\Http\\Kernel->Illuminate\\Foundation\\Http\\{closure}(Object(Illuminate\\Http\\Request))","41 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9553): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))","42 /opt/bitnami/apps/dreamfactory/htdocs/vendor/barryvdh/laravel-cors/src/HandleCors.php(52): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))","43 [internal function]: Barryvdh\\Cors\\HandleCors->handle(Object(Illuminate\\Http\\Request), Object(Closure))","44 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)","45 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17932): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))","46 [internal function]: DreamFactory\\Http\\Middleware\\FirstUserCheck->handle(Object(Illuminate\\Http\\Request), Object(Closure))","47 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)","48 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(12881): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))","49 [internal function]: Illuminate\\View\\Middleware\\ShareErrorsFromSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))","50 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)","51 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(11504): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))","52 [internal function]: Illuminate\\Session\\Middleware\\StartSession->handle(Object(Illuminate\\Http\\Request), Object(Closure))","53 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)","54 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(12622): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))","55 [internal function]: Illuminate\\Cookie\\Middleware\\AddQueuedCookiesToResponse->handle(Object(Illuminate\\Http\\Request), Object(Closure))","56 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)","57 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(12561): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))","58 [internal function]: Illuminate\\Cookie\\Middleware\\EncryptCookies->handle(Object(Illuminate\\Http\\Request), Object(Closure))","59 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)","60 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2978): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))","61 [internal function]: Illuminate\\Foundation\\Http\\Middleware\\CheckForMaintenanceMode->handle(Object(Illuminate\\Http\\Request), Object(Closure))","62 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)","63 [internal function]: Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(Illuminate\\Http\\Request))","64 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9535): call_user_func(Object(Closure), Object(Illuminate\\Http\\Request))","65 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2251): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))","66 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2234): Illuminate\\Foundation\\Http\\Kernel->sendRequestThroughRouter(Object(Illuminate\\Http\\Request))","67 /opt/bitnami/apps/dreamfactory/htdocs/public/index.php(53): Illuminate\\Foundation\\Http\\Kernel->handle(Object(Illuminate\\Http\\Request))","68 {main}"]}}


#16

Sorry, in DF 2 you should use:

event.request.payload.resource instead of event.request.body.record


#17

Hi,

I’ve modified my script.

var user = event.request.payload.resource;
var payload = {
  "to": [
    {
      "name": "Allen Sandiego",
      "email": "email@domain.com"
    }
  ],
  "subject": "Welcome",
  "body_html": "{name},<br/><br/>You have successfully registered!",
  "from_name": "Allen Sandiego",
  "from_email": "email@domain.com",
  "name": user.email
}
platform.api('email', payload);

I get another error.

{“error”:{“context”:null,“message”:“Cannot read property ‘email’ of undefined”,“code”:500,“trace”:[“0 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Handlers/Events/ServiceEventHandler.php(149): DreamFactory\Core\Handlers\Events\ServiceEventHandler->handleEventScript(‘user.register.p…’, Array)”,“1 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Handlers/Events/ServiceEventHandler.php(102): DreamFactory\Core\Handlers\Events\ServiceEventHandler->onPostProcess(‘user.register.p…’, Object(DreamFactory\Core\Events\ResourcePostProcess))”,“2 [internal function]: DreamFactory\Core\Handlers\Events\ServiceEventHandler->onResourcePostProcess(Object(DreamFactory\Core\Events\ResourcePostProcess))”,“3 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9772): call_user_func_array(Array, Array)”,“4 [internal function]: Illuminate\Events\Dispatcher->Illuminate\Events\{closure}(Object(DreamFactory\Core\Events\ResourcePostProcess))”,“5 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9717): call_user_func_array(Object(Closure), Array)”,“6 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(6015): Illuminate\Events\Dispatcher->fire(Object(DreamFactory\Core\Events\ResourcePostProcess))”,“7 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Resources/BaseRestResource.php(108): Illuminate\Support\Facades\Facade::__callStatic(‘fire’, Array)”,“8 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Resources/BaseRestResource.php(108): Illuminate\Support\Facades\Event::fire(Object(DreamFactory\Core\Events\ResourcePostProcess))”,“9 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Components/RestHandler.php(181): DreamFactory\Core\Resources\BaseRestResource->postProcess()”,“10 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Components/RestHandler.php(224): DreamFactory\Core\Components\RestHandler->handleRequest(Object(DreamFactory\Core\Utility\ServiceRequest), ‘’)”,“11 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Components/RestHandler.php(172): DreamFactory\Core\Components\RestHandler->handleResource(Array)”,“12 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Services/BaseRestService.php(65): DreamFactory\Core\Components\RestHandler->handleRequest(Object(DreamFactory\Core\Utility\ServiceRequest), ‘register’)”,“13 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Utility/ServiceHandler.php(57): DreamFactory\Core\Services\BaseRestService->handleRequest(Object(DreamFactory\Core\Utility\ServiceRequest), ‘register’)”,“14 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17588): DreamFactory\Core\Utility\ServiceHandler::processRequest(‘v2’, ‘user’, ‘register’)”,“15 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17564): DreamFactory\Http\Controllers\RestController->handleService(‘v2’, ‘user’, ‘register’)”,“16 [internal function]: DreamFactory\Http\Controllers\RestController->handlePOST(‘v2’, ‘user’, ‘register’)”,“17 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8842): call_user_func_array(Array, Array)”,“18 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8911): Illuminate\Routing\Controller->callAction(‘handlePOST’, Array)”,“19 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8891): Illuminate\Routing\ControllerDispatcher->call(Object(DreamFactory\Http\Controllers\RestController), Object(Illuminate\Routing\Route), ‘handlePOST’)”,“20 [internal function]: Illuminate\Routing\ControllerDispatcher->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,“21 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9553): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“22 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17850): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“23 [internal function]: DreamFactory\Http\Middleware\AccessCheck->handle(Object(Illuminate\Http\Request), Object(Closure))”,“24 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)”,“25 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“26 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9535): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“27 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8892): Illuminate\Pipeline\Pipeline->then(Object(Closure))”,“28 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8877): Illuminate\Routing\ControllerDispatcher->callWithinStack(Object(DreamFactory\Http\Controllers\RestController), Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), ‘handlePOST’)”,“29 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7831): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), ‘DreamFactory\\Ht…’, ‘handlePOST’)”,“30 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7802): Illuminate\Routing\Route->runWithCustomDispatcher(Object(Illuminate\Http\Request))”,“31 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7455): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))”,“32 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,“33 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9553): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“34 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“35 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9535): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“36 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7456): Illuminate\Pipeline\Pipeline->then(Object(Closure))”,“37 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7444): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))”,“38 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7429): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))”,“39 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2304): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))”,“40 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))”,“41 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9553): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“42 /opt/bitnami/apps/dreamfactory/htdocs/vendor/barryvdh/laravel-cors/src/HandleCors.php(52): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“43 [internal function]: Barryvdh\Cors\HandleCors->handle(Object(Illuminate\Http\Request), Object(Closure))”,“44 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)”,“45 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17932): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“46 [internal function]: DreamFactory\Http\Middleware\FirstUserCheck->handle(Object(Illuminate\Http\Request), Object(Closure))”,“47 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)”,“48 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(12881): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“49 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))”,“50 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)”,“51 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(11504): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“52 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))”,“53 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)”,“54 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(12622): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“55 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))”,“56 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)”,“57 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(12561): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“58 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))”,“59 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)”,“60 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2978): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“61 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))”,“62 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)”,“63 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“64 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9535): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“65 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2251): Illuminate\Pipeline\Pipeline->then(Object(Closure))”,“66 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2234): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))”,“67 /opt/bitnami/apps/dreamfactory/htdocs/public/index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))”,“68 {main}”]}}

Here’s my payload to /user/register (POST)

{
  "email": "email@domain.com",
  "first_name": "Allen",
  "last_name": "Sandiego",
  "new_password": "password"
}

Thanks for all the help.


#18

Hello @allensandiego, in this case the user is an array.
probably if you make user[0].name will work, but recommended is to use each.

I did a complete implementation using their examples, step by step follows below:
I relied on the example of push notification that is in doc.

1 - Event script (system.user.post.post_process)


this script:

// system.user.post.post_process
// This script runs AFTER create users.
// records are in array event.request.payload.resource.

var lodash = require("lodash.min.js");

if (event.request.payload.resource) {
    
    lodash._.each(event.request.payload.resource, function( user ) {
        var payload = {
            subject: "Welcome",
            body_html: "{name},<br/><br/>You have successfully registered!",
            from_name: "Allen Sandiego",
            from_email: "email@domain.com",
            name: user.name,
            to: {
                name: user.name,
                email: user.email
            }
        };
        
        // service name is 'email', in this case is a Mandrill email service
        var send = platform.api.post("email", payload);
        
        // output result to htdocs/storage/logs/dreamfactory.log
        var_dump(send);
    });
}
```

**2 - User create form**
<img src="/uploads/dreamfactory/original/1X/3727ec10af78651a96537adeb9106ddfc16a8b49.jpg" width="668" height="500">

**3 - Console log output (var_dump)**
<img src="/uploads/dreamfactory/original/1X/a123798e1c53e189babd7470e50cfea5cd755061.jpg" width="690" height="279">

**4 - Received email in my inbox**
<img src="/uploads/dreamfactory/original/1X/c35d0a92df4eb3734ab3e169cbbadf1b9eebe465.jpg" width="690" height="313">

#19

Hi,

This is what I had originally.

During POST in “/user/registration” in Chrome Rest Client, the response returns:

{"success":true}

However, I receive no email.

I also tried getting the first item in the array using user[0]. I get another error.

{“error”:{“context”:null,“message”:“Cannot read property ‘0’ of undefined”,“code”:500,“trace”:[“0 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Handlers/Events/ServiceEventHandler.php(149): DreamFactory\Core\Handlers\Events\ServiceEventHandler->handleEventScript(‘user.register.p…’, Array)”,“1 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Handlers/Events/ServiceEventHandler.php(102): DreamFactory\Core\Handlers\Events\ServiceEventHandler->onPostProcess(‘user.register.p…’, Object(DreamFactory\Core\Events\ResourcePostProcess))”,“2 [internal function]: DreamFactory\Core\Handlers\Events\ServiceEventHandler->onResourcePostProcess(Object(DreamFactory\Core\Events\ResourcePostProcess))”,“3 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9772): call_user_func_array(Array, Array)”,“4 [internal function]: Illuminate\Events\Dispatcher->Illuminate\Events\{closure}(Object(DreamFactory\Core\Events\ResourcePostProcess))”,“5 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9717): call_user_func_array(Object(Closure), Array)”,“6 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(6015): Illuminate\Events\Dispatcher->fire(Object(DreamFactory\Core\Events\ResourcePostProcess))”,“7 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Resources/BaseRestResource.php(108): Illuminate\Support\Facades\Facade::__callStatic(‘fire’, Array)”,“8 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Resources/BaseRestResource.php(108): Illuminate\Support\Facades\Event::fire(Object(DreamFactory\Core\Events\ResourcePostProcess))”,“9 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Components/RestHandler.php(181): DreamFactory\Core\Resources\BaseRestResource->postProcess()”,“10 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Components/RestHandler.php(224): DreamFactory\Core\Components\RestHandler->handleRequest(Object(DreamFactory\Core\Utility\ServiceRequest), ‘’)”,“11 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Components/RestHandler.php(172): DreamFactory\Core\Components\RestHandler->handleResource(Array)”,“12 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Services/BaseRestService.php(65): DreamFactory\Core\Components\RestHandler->handleRequest(Object(DreamFactory\Core\Utility\ServiceRequest), ‘register’)”,“13 /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Utility/ServiceHandler.php(57): DreamFactory\Core\Services\BaseRestService->handleRequest(Object(DreamFactory\Core\Utility\ServiceRequest), ‘register’)”,“14 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17588): DreamFactory\Core\Utility\ServiceHandler::processRequest(‘v2’, ‘user’, ‘register’)”,“15 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17564): DreamFactory\Http\Controllers\RestController->handleService(‘v2’, ‘user’, ‘register’)”,“16 [internal function]: DreamFactory\Http\Controllers\RestController->handlePOST(‘v2’, ‘user’, ‘register’)”,“17 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8842): call_user_func_array(Array, Array)”,“18 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8911): Illuminate\Routing\Controller->callAction(‘handlePOST’, Array)”,“19 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8891): Illuminate\Routing\ControllerDispatcher->call(Object(DreamFactory\Http\Controllers\RestController), Object(Illuminate\Routing\Route), ‘handlePOST’)”,“20 [internal function]: Illuminate\Routing\ControllerDispatcher->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,“21 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9553): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“22 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17850): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“23 [internal function]: DreamFactory\Http\Middleware\AccessCheck->handle(Object(Illuminate\Http\Request), Object(Closure))”,“24 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)”,“25 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“26 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9535): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“27 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8892): Illuminate\Pipeline\Pipeline->then(Object(Closure))”,“28 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8877): Illuminate\Routing\ControllerDispatcher->callWithinStack(Object(DreamFactory\Http\Controllers\RestController), Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), ‘handlePOST’)”,“29 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7831): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), ‘DreamFactory\\Ht…’, ‘handlePOST’)”,“30 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7802): Illuminate\Routing\Route->runWithCustomDispatcher(Object(Illuminate\Http\Request))”,“31 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7455): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))”,“32 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,“33 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9553): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“34 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“35 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9535): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“36 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7456): Illuminate\Pipeline\Pipeline->then(Object(Closure))”,“37 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7444): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))”,“38 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7429): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))”,“39 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2304): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))”,“40 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))”,“41 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9553): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“42 /opt/bitnami/apps/dreamfactory/htdocs/vendor/barryvdh/laravel-cors/src/HandleCors.php(52): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“43 [internal function]: Barryvdh\Cors\HandleCors->handle(Object(Illuminate\Http\Request), Object(Closure))”,“44 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)”,“45 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17932): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“46 [internal function]: DreamFactory\Http\Middleware\FirstUserCheck->handle(Object(Illuminate\Http\Request), Object(Closure))”,“47 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)”,“48 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(12881): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“49 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))”,“50 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)”,“51 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(11504): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“52 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))”,“53 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)”,“54 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(12622): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“55 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))”,“56 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)”,“57 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(12561): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“58 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))”,“59 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)”,“60 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2978): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“61 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))”,“62 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9545): call_user_func_array(Array, Array)”,“63 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,“64 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9535): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,“65 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2251): Illuminate\Pipeline\Pipeline->then(Object(Closure))”,“66 /opt/bitnami/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2234): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))”,“67 /opt/bitnami/apps/dreamfactory/htdocs/public/index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))”,“68 {main}”]}}

Regards,
Allen


#20

@allensandiego please, place this script entirely, and nothing more, and test again.