Skip to main content
Question

API Rest FME Custom Body request and custom response

  • November 27, 2024
  • 7 replies
  • 72 views

fred.haan
Contributor
Forum|alt.badge.img+1

Hello,  

I am using the 2024 versions of FME (Form & Flow).  

I would like to create an FME Form workspace that will be deployed on FME Flow and later called via the FME REST API.  
In this API call (POST), I would like to include structured information in the request body that the FME Workbench can process.  

For example, the request body could look like this:  

```json
{
    "entities": [
        {
            "schemaName": "xxxxx",
            "entityName": "xxxx",
            "fieldNames": [ 
                "ID",
                "NR_ATT"
            ]
        }
    ],
    "whereClause": "ID = 'xxxxx'",    
    "constraint": "FIRST"
}
```  

I would also like the response of the execution to contain structured information, which could include standard execution feedback along with additional custom data.  

For example, the response could look like this:  

```json
{
    "rows": [
        {
            "fields": [
                {"schemaName": "xxxx", "entityName": "yyyy", "fieldName": "zzzz", "fieldValue": "aaaaa"},
                {"schemaName": "xxxx", "entityName": "yyyy", "fieldName": "pppp", "fieldValue": "bbbbb"}
            ]
        }
    ]
}
```  

How should I proceed to configure my Workbench (inputs and outputs)?  
What settings should I use to publish this Workbench to FME Flow?  

Does anyone have a simple example or step-by-step instructions that could help?  

 

Thanks a lot

 

7 replies

davtorgh
Contributor
Forum|alt.badge.img+10
  • Contributor
  • November 28, 2024

Hi ​@fred.haan,

I’m not sure if I have correctly understood your requirements, but I can tell you that a workspace can be run using FME Flow (former FME Server) rest API /transformations/transact/{repository}/{workspace} (sycronous) or /transformations/submit/{repository}/{workspace} (asyncronous).

I think the article Submitting a Job through the FME Server REST API could be a good tutorial.

Hope that helps!

 


fred.haan
Contributor
Forum|alt.badge.img+1
  • Author
  • Contributor
  • December 3, 2024
davtorgh wrote:

Hi ​@fred.haan,

I’m not sure if I have correctly understood your requirements, but I can tell you that a workspace can be run using FME Flow (former FME Server) rest API /transformations/transact/{repository}/{workspace} (sycronous) or /transformations/submit/{repository}/{workspace} (asyncronous).

I think the article Submitting a Job through the FME Server REST API could be a good tutorial.

Hope that helps!

 

Hello,

In fact I want to know if a “json response” can be different that the std response and add additional information ?

 


davtorgh
Contributor
Forum|alt.badge.img+10
  • Contributor
  • December 4, 2024

Ok, now it’s clearer.

The right way is the webhook.

Publish to FME Flow a workspace that produce a json output with a json writer (in attachment there is a simple example) with the Data Streaming service and, eventually, the Data Download service (which isn’t striclty necessary in this use case).

When the workspace is published, in FME Flow go to the Run Workspace page, select the workspace (be sure to select the Data Streaming service) and, in the Advanced section, follow the instruction to create a webhook. Be sure to download the token file, because you have only one chance. This file contains all the information you need to run the workspace via a webhook.

Here is a simple call using curl:

curl -H "Authorization: fmetoken token=<your_token>" https://<your_fme_flow_url>/fmedatastreaming/<your_repository>/webhook-sample.fmw?

and here is the output:

[
 {
        "json_featuretype" : "webhook-sample",
        "_creation_instance" : "0",
        "random_number" : 9
 },
 {
        "json_featuretype" : "webhook-sample",
        "_creation_instance" : "1",
        "random_number" : 0
 },
 {
        "json_featuretype" : "webhook-sample",
        "_creation_instance" : "2",
        "random_number" : 1
 },
 {
        "json_featuretype" : "webhook-sample",
        "_creation_instance" : "3",
        "random_number" : 1
 },
 {
        "json_featuretype" : "webhook-sample",
        "_creation_instance" : "4",
        "random_number" : 8
 }
]

Hope that helps!


fred.haan
Contributor
Forum|alt.badge.img+1
  • Author
  • Contributor
  • January 3, 2025

Hello,

 

Thanks for this answser. 

Would it be possible to use the API transact and generate a custom response body that include these information ?

I don’t know how to customize a response body with api transact

Or the only way is to use a webhook ?

 

Thanks


virtualcitymatt
Celebrity
Forum|alt.badge.img+34
fred.haan wrote:

Hello,

 

Thanks for this answser. 

Would it be possible to use the API transact and generate a custom response body that include these information ?

I don’t know how to customize a response body with api transact

Or the only way is to use a webhook ?

 

Thanks

I think so far the only opportunity is to to use data streaming service if you want to get a repones back which includes data.

Is there any specific reason why you want to use the transact call instead of the datastreaming service?

There is an idea here to have FME Server support the functionality of the different services via the standard REST API

 

Interestingly, I have noticed in the version 4 of the REST api there are a few lines in the response which may indicate that this functionality is coming or is included but hidden.

e.g, 

"resultDatasetDownloadUrl"

This is no indication in the documentation how to control the response yet. 

I would really like to see this functionality in FME Flow


fred.haan
Contributor
Forum|alt.badge.img+1
  • Author
  • Contributor
  • January 3, 2025

Hello,

I could used  a datastreaming service.

I try to launch it through au curl command but i have an error. Do you have any idea , is a a right way to test. Here is the command I use:

curl -X POST "http://<fmeserver>:80/fmedatastreaming" \
-H "Authorization: Bearer 98d72132-5ad4-6b1b-9986-88e1fb00ce5a" \
-H "Content-Type: application/json" \
-d '{
  "repository": "Samples",
  "workspace": "transacSample.fmw",
  "parameters": {
    "input_data": "sample_data",
    "custom_message": "Traitement terminé avec succès"
  }
}'
 

But the erreor is “curl: (3) URL rejected: Port number was not a decimal number between 0 and 65535”  Do you know where I could get an exemple ?

 

Thanks

 

 

 


virtualcitymatt
Celebrity
Forum|alt.badge.img+34

The Authorization isn’t quite right. 

the value should be "Authorization: fmetoken token=<your_token>" as ​@davtorgh suggested in their post.

I’m also not hugely familiar with curl and the specific required syntax, but a quick search of your error turned up this stack overflow thread.  

https://stackoverflow.com/questions/50784321/curl-error-3-port-number-ended-with

Essentially It looks like you just need to work on your syntax. ChatGPT is probably a pretty good tool to help you work through the issues here. And it wont take several days to respond...unlike me :-D

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings