7. Genja API¶
7.1. Endpoints¶
service status: https://generator.geneea.com/status
curl -v https://generator.geneea.com/status
template validation:
https://generator.geneea.com/validate
curl https://generator.geneea.com/validate \ -H 'Authorization: Basic ********************' \ -H 'Content-Type: application/json' \ --data '{"templates": [ {"id": "1", "name": "test", "body": "Hello"} ], "data": {} }' # Replace ******************** with base64-encoded username:password # On Windows, use \" instead of " and " instead of '
generation:
https://generator.geneea.com/generate
curl https://generator.geneea.com/generate \ -H 'Authorization: Basic ********************' \ -H 'Content-Type: application/json' \ --data '{"templates": [ {"id": "1", "name": "test", "body": "Hello"} ], "data": {} }' # Replace ******************** with base64-encoded username:password # On Windows, use \" instead of " and " instead of '
7.2. Generation¶
The following code snippets show how to generate
curl https://generator.geneea.com/generate -H "Authorization: Basic ********************" -H 'Content-Type: application/json' --data @example.request.json # Replace ******************** with base64-encoded username:password # On Windows, use \" instead of " and " instead of 'As
example.request.json
, you can use the following file containing the template and data:{ "templates": [ { "id": "tmpl-1", "name": "testing template", "body": "Do 2. kola v {{district|name|morph('Case=Loc')}} postoupili {{candidates[0]|name}} a {{candidates[1]|name}}." } ], "data": { "year": 2018, "district": { "name": "Opava" }, "candidates": [ { "name": "Herbert Pavera (TOP 09)", "votesPct": 36.27 }, { "name": "Simona Horáková (ANO)", "votesPct": 21.54 }, { "name": "Vladimír Tancík (NK)", "votesPct": 12.14 } ] } }import requests def callGenja(input): url = 'https://generator.geneea.com/generate' headers = { 'content-type': 'application/json', 'Authorization': 'Basic ********************' } return requests.post(url, json=input, headers=headers).json() req = { "templates": [ { "id": "tmpl-1", "name": "testing template", "body": "Do 2. kola v {{district|name|morph('Case=Loc')}} postoupili {{candidates[0]|name}} a {{candidates[1]|name}}." } ], "data": { "year": 2018, "district": { "name": "Opava" }, "candidates": [ { "name": "Herbert Pavera (TOP 09)", "votesPct": 36.27 }, { "name": "Simona Horáková (ANO)", "votesPct": 21.54 } ] } } print(callGenja(req))function callGenja(user, pwd, req) { var url = "https://generator.geneea.com/generate" var params = { "contentType": "application/json", "headers": { "Authorization": "Basic " + Utilities.base64Encode(user + ":" + pwd), }, "payload": JSON.stringify(req) } var response = UrlFetchApp.fetch(url, params=params); return JSON.parse(response.getContentText()); } var req = { "templates": [ { "id": "tmpl-1", "name": "testing template", "body": "Do 2. kola v {{district|name|morph('Case=Loc')}} postoupili {{candidates[0]|name}} a {{candidates[1]|name}}." } ], "data": { "year": 2018, "district": { "name": "Opava" }, "candidates": [ { "name": "Herbert Pavera (TOP 09)", "votesPct": 36.27 }, { "name": "Simona Horáková (ANO)", "votesPct": 21.54 } ] } } Logger.log(callGenja(<USER>, <PASSWORD>, req))
The result of the generation is:
{ "id": "tmpl-1-2021-04-23T15:33:29", "article": "Do 2. kola v Opavě postoupili Herbert Pavera (TOP 09) a Simona Horáková (ANO).", "messages": [] }