Solved

How to do a post-request with httpcaller, filling the body by data from a transformer without sending the data within the post?

  • 23 February 2022
  • 10 replies
  • 108 views

Badge

Hi, I try to request data from an api by a POST-request with httpcaller. Every post works fine when I set the parameter geodata in the body manually like this:

{

"geodata": ["FCA","FF"],

..."

}

These are identifiers of features, which I want insert dynamically by an other transformer (Attributekeeper).

The attributekeeper delivers one field called BSTs with this content: "MLLF","DPU","WWM"

 

{

"geodata": [@Value(BSTs)],

..."

}

 

As soon as I activate the connection between attributekeeper and httpcaller, the api sends a "403" not allowed. I suppose, that the httpcaller sends the data of the transformer attributekeeper within the POST, what is not allowed by the api. But strange is, that I send allready the authentification-token to the httpcaller to use it in the header. This works...

 

workspaceAny ideas are welcome ;-)

Best regards, Christoph

icon

Best answer by takashi 23 February 2022, 18:36

View original

10 replies

Userlevel 4

Consider using the JSONTemplater to generate the request data and using the output in the HTTPCaller.

Badge

Thanks David!

 It is still the same problem: 

Now I am configuring the json-body with a jsontemplater and some string-operations, targeting the field "_body". 

When I copy manually the content of the transformer-output to the body of the httpCaller without connection, the api-call works! When I connect the output of the attributekeeper to the httpcaller and set the Upload body on _body.

I get a reject. Perhaps the logfile helps.

Is there a possibility to see what is sended by the httpcaller?

 

HTTPPost_BatchTrigger (HTTPFactory): Received HTTP response header: 'HTTP/1.1 403 Forbidden' from 'https://gateway.hub.db.de/web4bpawetter/forecast/batch'
HTTPPost_BatchTrigger (HTTPFactory): An error occurred w

 

 

imageimage

Userlevel 4

Thanks David!

 It is still the same problem: 

Now I am configuring the json-body with a jsontemplater and some string-operations, targeting the field "_body". 

When I copy manually the content of the transformer-output to the body of the httpCaller without connection, the api-call works! When I connect the output of the attributekeeper to the httpcaller and set the Upload body on _body.

I get a reject. Perhaps the logfile helps.

Is there a possibility to see what is sended by the httpcaller?

 

HTTPPost_BatchTrigger (HTTPFactory): Received HTTP response header: 'HTTP/1.1 403 Forbidden' from 'https://gateway.hub.db.de/web4bpawetter/forecast/batch'
HTTPPost_BatchTrigger (HTTPFactory): An error occurred w

 

 

imageimage

Difficult to say, I do not have enough information about either the API specification or the complete configuration of the HTTPCaller to pinpoint the issue.

Perhaps try activating the debug messages in the log file.

https://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_Workbench/Workbench/Viewing_the_Log.htm

Userlevel 2
Badge +17

Thanks David!

 It is still the same problem: 

Now I am configuring the json-body with a jsontemplater and some string-operations, targeting the field "_body". 

When I copy manually the content of the transformer-output to the body of the httpCaller without connection, the api-call works! When I connect the output of the attributekeeper to the httpcaller and set the Upload body on _body.

I get a reject. Perhaps the logfile helps.

Is there a possibility to see what is sended by the httpcaller?

 

HTTPPost_BatchTrigger (HTTPFactory): Received HTTP response header: 'HTTP/1.1 403 Forbidden' from 'https://gateway.hub.db.de/web4bpawetter/forecast/batch'
HTTPPost_BatchTrigger (HTTPFactory): An error occurred w

 

 

imageimage

Insert a Logger before the HTTPCaller then run. You can see the content of "_body" in the log.

Badge

Insert a Logger before the HTTPCaller then run. You can see the content of "_body" in the log.

I can see the content also within the transformer cache: 

{ "geodata" : [ "HBKB","HFLL","HRIN","HM","HL","HKLG","HVTH","HLH","HBDE","HHMS","HLST","HLBB","HHZH","HRAH","HEKP" ], "from" : "2022-02-15T00:00:00", "to" : "2022-02-15T23:59:59", "fields" : "PREC_6H,PROB_PREC_MAX_6H", "wait" : false, "flatten" : true, "si" : false }

 The httpcaller works when I put the content manually in the transformers upload body and disable the connection. When it is streamed by connection it goes wrong.

imageThank you for your hints.

Userlevel 4

Insert a Logger before the HTTPCaller then run. You can see the content of "_body" in the log.

The problem is that you're sending the text string "_response_body", and not the contents of the attribute named "_response_body". Make sure to select the attribute name from the context menu rather than typing it in.

Badge

Insert a Logger before the HTTPCaller then run. You can see the content of "_body" in the log.

Hm, I don't think so. This is the POST-request i am sending:

imageAnd the api-response will be in the "Response Body Attribute" named "_response_body". image

Userlevel 4

Insert a Logger before the HTTPCaller then run. You can see the content of "_body" in the log.

Ouch, must get better glasses. You're right, of course.

Userlevel 2
Badge +17

Insert a Logger before the HTTPCaller then run. You can see the content of "_body" in the log.

According to the screenshot you have posted, a part of the authorization value is the value of feature attribute called "JWT".

In this case, the feature coming from the AttributeKeeper (connection A in the screenshot below) should have both "JWT" and "_body".

Make sure that.

If the feature coming from B contains "JWT" but the A feature doesn't, you will have to merge "JWT" from B to A before inputting to the HTTPCaller.

image

Badge

Insert a Logger before the HTTPCaller then run. You can see the content of "_body" in the log.

Dear takashi. Thanks a lot for your idea and exelent input.

I merged the two connections and it works ... yeah!

Reply