1

I have been trying to populate my variable bar with json fields from curl's POSTFIELDS attribute when invoking my workflow from an API using PHP. Below is a simple json passed when invoking the endpoint not as part of the URL but hidden POSTed data:

{"salesValue":5000,"authorId":2}

The properties above should be injected in Formatter Node where I generate the SQL statetement used by the ODBC driver to query our back-end database. I have been told that I can only do this, for now, by using the SCRIPT Node as I do not recall C# as having support for manipulating JSON Object out of the box. If I am behind with regards to that someone please lead me to an answer.

Question is: does Flowger support JSON Serialization, Deserialization, Decoding and/or encoding? There is a framework called JSON.Net for example. Can I use this if I want to manipulate my fgRequestBody property frfom my variable bar?

pnuts
  • 58,317
  • 11
  • 87
  • 139
scruffycoder86
  • 527
  • 1
  • 5
  • 24

1 Answers1

0

Try the below steps to get the desired results:
1 - Add a variable bar with two special properties: FgRequestBody and FgRequestContentType. Make sure that you specify the content type in the workflow, which will be application/json in your instance.
2 - Add a 'JSON Convert' directly after the start node and point your variable bar FgRequestBody to the input of Json on the Json Convert. This will convert json to xml.
3 - Add a 'XFormat' node and plug the xml output from the Json Convert to the 'XML Document' property. Right click on the node and add a new custom property with the name of the field that you would like to extract. In the custom property value, add the xpath to the value. In the Expression property of the node, add your sql statement e.g.

select * from tableName where name = '{customProperty}'

The results from this will be your sql query.

Troubleshooting Tip:
Use Postman Add-In (Chrome) or RESTClient (Firefox) to verify the results. You should see the node generation in the activity log within Flowgear. If you do not see this, then add a AllowedOrigin of * in your Flowgear Site properties. See the following for reference to this:http://en.wikipedia.org/wiki/Cross-origin_resource_sharing

DJJ
  • 203
  • 1
  • 2
  • 9
  • Thanks Dayne for your simple approach to doing this. As i was trying out your suggestion I notice I do not have any node named XFormat on my console. Could this node have different names or perhaps is available for certain users or what? – scruffycoder86 Oct 02 '14 at 10:48
  • You're welcome, you could also use the XPath node followed by the formatter node as it does the same as the XFormat node. The XFormat node is just a combination of both the above mentioned nodes. However, the XFormat should be available to you now. – DJJ Oct 02 '14 at 11:02
  • The XFormat node was really helpful to grab the requestBody json data. Basically I now have: 5000 2 as my XMLDocument which I should provide an xpath from. I created the following xpaths for my values: salesValue:root/saleValue and authorId:root/authorId respectively. Clearly my xpath values are wrong because I end up with this error: – scruffycoder86 Oct 02 '14 at 12:32
  • You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':root/saleValue AND `Book`.`author_id` = "authorId:root/authorId"' at line 1...... The custom properties from the XFormat node are defined as input/output so that I can map each to the Formatter node where I create the sql query from. – scruffycoder86 Oct 02 '14 at 12:37
  • Turns out I was connecting the XFormat node to the Formatter node to create the SQL query where I could use the XFormat node to do that. However, eversince I removed the redundant node I get this error: (XFormat 1.0.0.1): Namespace prefix 'salesValue' is not defined... Could you point me to the right direction as to why? – scruffycoder86 Oct 02 '14 at 12:53
  • When you specify the xPath in the xFormat node, then you don't need to add property name within the placeholder of the xpath, i.o.w you can just enter 'root/salesValue' and not 'salesValue:root/salesValue'. Hope that helps. We use this syntax 'customProp:xpath' in the xPath Matcher node. – DJJ Oct 03 '14 at 08:16
  • @DJJ,did you any solution for how to call flowgear workflow using POST method in API and store some value into database?please help me i am facing problem – sanjay Jan 02 '16 at 09:55
  • Hi Sanjay, did you check the Flowgear wiki page (Developer center) out for developers? You should get some meaningful assistance there. Alternatively, I would suggest to create a new post as your question is not directly related to the issue of the post. Regards – DJJ Jan 08 '16 at 11:45