Question

Using REST API submit, how to send email

  • 5 October 2015
  • 9 replies
  • 8 views

Hello!

 

 

I'm developing a web application that sends requests to an FME server to run some pre-defined workspaces. 

 

 

I'm passing in some parameters (including geometries as GeoJSON) as published Parameters, and I am using the rest API endpoint /fmerest/v2/transformations/commands/submit/REPOSITORY/WORKSPACE

 

 

This seems to work fine, I get a job ID back and the logs tells me that the job has run. 

 

 

However, and here lies the problem: As these jobs can be long-running and I don't want the hassle of polling FME server from my web app I would like FME server to send the result as an email to an email-address specified when the job is submitted (IE: not hard-coded in FME server)

 

 

 

After some googling and chats with our FME experts it seems like this should be possible using the JobSubmitter service (http://docs.safe.com/fme/2014/html/FME_Server_Documentation/Default.htm#web_services/job_submitter_service.htm) and setting the opt_requesteremail property.

 

 

However: to my understanding the jobsubmitter only works with Query parameters, and not a POST body like in the /fmerest/v2/transformations/commands/submit/REPOSITORY/WORKSPACE endpoint. I want to use a POST body as I'm rather sure that I will have published parameters (GeoJSON polygons f.ex) that exeeds the maximum URL length)

 

 

So: the simple question is: How do I use the fmerest/v2/transformations/commands/submit/REPOSITORY/WORKSPACE endpoint and specify an email to send the result to? 

 

 

I've tried setting NMDirectives.successTopics and NMDirectives.failureTopics to JOBSUBMITTER_ASYNC_JOB_SUCCESS and JOBSUBMITTER_ASYNC_JOB_FAILURE in the PostBody and adding opt_requesteremail and opt_servicemode=async to the URL, but it does not seem to work.

 

 

This seems to me like a rather basic question, and I cannot possibly be the first who wants to do this? Any help appreciated!

 

 

9 replies

Userlevel 4
Hi

 

 

You're on the right track, you should probably not use the old job submitter service, but rather the new

 

<server>/transformations/commands/submit/<repository>/<workspace>

 

 

It will allow you to POST your published parameters.

 

 

For the notification, be sure to specify the topics JOBSUBMITTER_ASYNC_JOB_SUCCESS/FAILURE in the wizard when publishing the workspace on FME Server. On the server, create a new subscription that is alerted by these two topics and sends you the necessary signal (mail or other).

 

 

David

 

 
Badge +21
And it works correctly through the Jobsubmitter interface on fmeserver, so the topics are set correctly and the subscription is the standard subscription auto-generated by FME Server
Ah, great to know! This also cleared up something for me: Job submitter is the old way, the REST api Endpoint I'm using is the right one. 

 

 

However, I still cannot get this to work. I'm now sending a POST request to /fmerest/v2/transformations/commands/submit/REPO/WORKSPACE?opt_requesteremail=someone@example.com&opt_servicemode=async&opt_showresult=false

 

 

with the body: 

 

 

 

{ "FMEDirectives": {}, "NMDirectives": { "failureTopics": [ "JOBSUBMITTER_ASYNC_JOB_FAILURE" ], "successTopics": [ "JOBSUBMITTER_ASYNC_JOB_SUCCESS" ] }, "TMDirectives": { "rtc": false, "description": "description", "priority": 5, "tag": "linux" }, "publishedParameters": [ { "name": "geomCoordSys", "value": "EPSG:4326" }, { "name": "geomPoint", "value": "{\\"type\\":\\"Point\\",\\"coordinates\\":[10.677337646484375,59.923194464901037]}" }, { "name": "Buffer", "value": "552" } ], "subsection": "REST_SERVICE", "workspacePath": "\\"Analyseplattform_test/Enkel_geometri_og_buffer/Enkel_geometri_og_buffer.fmw\\"" }

 

 

 

 

However, the email_to parameter I try to set on NMDirectives disappears when I query 

 

/fmerest/v2/transformations/jobs/id/JOBID/request

 

 

This parameter (the email_to) seems to be the only missing parameter now, do you know how I can pass that in using the transformations/commands/submit/REPO/WORKSPACE path?
Userlevel 4
Hi

 

 

If you set the topics when publishing the workspace on FME Server, I do not think you need to set the NMDirectives.

 

 

Also, I guess that you've played around with the interactive API documentation at http://docs.safe.com/fme/html/FME_REST/? It's quite helpful in letting you construct sample requests.

 

 

David

 

 
Hmm.. This may be due to my lack of understanding of FME-terminology, but to me the main problem seems to be "How to specify the email to send the message to".

 

 

 

As far as I understand things, this should NOT be a Published parameter on the workspace itself, and for the jobsubmitter the email is specified using the opt_requesteremail property. However, I cannot find a way to add this property to the Post Body of a request to teh REST API. I've tried this:

 

 

-  setting it on the URL itself: did not work

 

- adding it to NMDirectives: did not work

 

- adding it to Published parameters list: Threw an error

 

 

So, I'm at a loss here. 
Badge
Hi Guys,

 

The transformation/commands api seems to support "NMDirectives" so you can specify the success and failure topics but it doesn't seem to support any other NMDirectives.  So I don't think that can work because you can't pass the email_to address.

 

 

Can you use the Job Submitter Service?  Then this should be possible with POST or GET if you specify the following opt parameters:

 

opt_servicemode=async

 

opt_requesteremail = <emailaddress>

 

 

I'll follow-up in more detail via the support case we have for you.

 

Ken 

 

 
Yeah, I found out that adding email_to to the NMDirectives did not work. Strange, is there any logical reason for that?

 

 

As much as I would like to use the REST API I'd rather have a working solution, so after "arguing" a bit with the Job Submitter Service (and after some more thinking, the Data Download Servcie). This works, but I ran into some other trouble (related to passing GeoJSON as a published parameter). I at first has to do some replacing og {, [ , and ", (to <bracketstart> etc etc) But SigTill found another way to define a PublishedParameter Geometry, and this solved the issue.

 

 

So: current status: This is now working using the DataDownload Service, altough I would really like this to work using the REST API as well. Rather difficult to dig around in several disconnected APIs, trying to understand what works and not. 
Badge
Yes agreed,

 

We have a longstanding task to include the services in the REST API. The other thing that would help is to allow full messages in the NMDirectives for the existing transformation methods - to be honest this is the first time that particular issue has come up that I know of.

 

Thanks 

 

Ken
Great to hear you have it on the drawing board at least! 

 

 

Hmm, maybe my use-case is a bit strange then? I would think it fairly common to be able to start a job using the REST api and have a response sent to a user-defined email. Or do you think this is an uncommon use-case or do people solve it in other ways?

 

 

The most frustrating thing for a developer not knowing FME-jargon is juggeling the concepts of REST-api, Jobsubmitter and DownloadService (and maybe more). I guess there are reasons behind this division, but they are very unclear to me and they do make the whole API more difficult to wrap your head around. 

 

 

Anyways: This seems to be working now, thanks for all suggestions and help from both David and Ken!

 

 

Reply