Unable to create email templates via REST (with Swagger or coded request)


#1

I am attempting to create email templates via the REST API (instead of the system GUI) with the thought that I would allow administrators to do so from inside the application I am building

I have made extensive efforts with both custom code/http requests as well as trying to create the templates via the swagger API doc explorer - all to no avail

Every time I try it gives me a 500 error - seemingly related to a failure to correctly handle the conversion of the TO array components (NAME and EMAIL) into strings for storage

To be clear, I am able to create the templates in the GUI, as well as being able to retrieve them via the REST API - though I have had spotty results on updates as well

Has anyone else been able to (can anyone else now) successfully use the REST API to create a template and if so what version are you on - I believe I have the newest version but here is the info JIC

Database Version: 1.9.0
DreamFactory Services Platform Version: 1.9.4
Admin Application Version: 1.0.12

Thanks a bunch
Ben


#2

Tested this in the current version (DreamFactory 2.0) and I don’t see an issue.

Request:

POST /api/v2/system/email_template

{"resource":
 [  {
   "name":"Template of Doom",
   "description":"The last good template",
   "to":"user@domain.com",
   "subject":"Choose wisely",
   "body_html":"Don't call me Junior!",
   "from_email":"dreamfactory@domain.com",
   "from_name":"DreamFactory"
  } ]
}

Response:

{ "resource": [ { "id": 7 } ] }

Went back to a 1.9.4 instance and tried the same. Works just like this:

Request:

POST /rest/system/email_template

{"record":
 [  {
   "name":"Template of Doom",
   "description":"The last good template",
   "to":"user@domain.com",
   "subject":"Choose wisely",
   "body_html":"Don't call me Junior!",
   "from_email":"dreamfactory@domain.com",
   "from_name":"DreamFactory"
  } ]
}

Response:

{ "resource": [ { "id": 5 } ] }

What’s the content of your payload? There must be something specific to your process that’s causing different behavior.


#3

The difference in my payload was that I was attempting to use the [EmailAddress] array for the “to” key as stated in the API doc examples (both with and without the “name” key)

I changed your payload example to use “to”:[{“email”:“user@domain.com”}] and it failed with the same error I was receiving before - an issue converting the array contents to a string

I have been able to successfully add templates with multiple addresses using just “to”:“address1,address2,etc” - which is fine for me and most helpful (thanks) - but will also add that it bombs if you have spaces between the addresses

In the end, its not perfect, but it will work for now


#5

I should also note that the same issue also applies to the “cc” and “bcc” as wells as the “from” and “reply_to” when attempting to use the array of email addresses as stated in the API Docs


for reference

to (array[EmailAddress], optional): Single or multiple receiver addresses.,

cc (array[EmailAddress], optional): Optional CC receiver addresses.,

bcc (array[EmailAddress], optional): Optional BCC receiver addresses.,

from (EmailAddress, optional): Required sender name and email.,

reply_to (EmailAddress, optional): Optional reply to name and email.,

EmailAddress {
name (string, optional): Optional name displayed along with the email address.,
email (string, optional): Required email address.
}


#6

Thank you for clarifying that you’re using an array of addresses and names! This is definitely broken. I am testing further and will report this to the dev team.


#7

Confirmed this behavior for POST and PATCH on email templates. Interestingly, in POST the template is still created despite the error code of 500, but "to": "Array" is stored instead of the POSTed value. In a PATCH call, the existing value is overwritten with "Array" despite also returning a 500.

Note that if you’re continuing to use 1.x this is not likely to be fixed once that version is deprecated.


#8

Cool deal

I was hesitant to use v2 as it is still listed as “beta” but I will keep that in mind as I go

Thanks for the help

BK


#9

The official production release of DreamFactory 2.0 launched on Bitnami today: https://bitnami.com/stack/dreamfactory

If you’re not using Bitnami just pull the latest code with git and you’ll be there.