{"componentChunkName":"component---src-templates-default-template-tsx","path":"/documentation/integration/CSV/CSV_AH/","result":{"data":{"asciidoc":{"id":"ec5bb116-6274-52c6-9405-b423329014d4","html":"<div id=\"toc\" class=\"toc\">\n<div id=\"toctitle\">Table of Contents</div>\n<ul class=\"sectlevel1\">\n<li><a href=\"#_introduction\">Introduction</a></li>\n<li><a href=\"#_prerequisites\">Prerequisites</a>\n<ul class=\"sectlevel2\">\n<li><a href=\"#_creating_attachment_vertex\">Creating attachment vertex</a></li>\n<li><a href=\"#_load_csv_data_to_the_attachment\">Load CSV data to the attachment</a></li>\n</ul>\n</li>\n<li><a href=\"#_using_the_action_handler\">Using the Action Handler</a></li>\n<li><a href=\"#_parameters_in_the_action_handler\">Parameters in the Action Handler</a>\n<ul class=\"sectlevel2\">\n<li><a href=\"#_calling_via_ki\">Calling via KI</a></li>\n<li><a href=\"#_resulting_spreadsheet\">Resulting Spreadsheet</a></li>\n</ul>\n</li>\n</ul>\n</div>\n<div class=\"sect1\">\n<h2 id=\"_introduction\">Introduction</h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>CSV ActionHandler converts an existing CSV file from the HIRO Graph (blob on ogit/Attachment) to a proper JSON formatted table, represented by an ogit/Document/Spreadsheet. In this guide we will walk through the process from adding an attachment to Quering the JSON formated table created by CSV ActionHandler.</p>\n</div>\n</div>\n</div>\n<div class=\"sect1\">\n<h2 id=\"_prerequisites\">Prerequisites</h2>\n<div class=\"sectionbody\">\n<div class=\"olist arabic\">\n<ol class=\"arabic\">\n<li>\n<p>Authenticate and retrieve a Graph Authentication token. Please refer to our documentation on <a href=\"https://core.engine.datagroup.de/help/specs/?url=definitions/auth.yaml#/\">HIRO Graph Auth API</a>.</p>\n</li>\n<li>\n<p>Id for the 'data-scope' (environment) you want to interact with. This value will be written to the ogit/_scope attribute. If omitted the default scope of your account will be used. Please be aware, that this may lead to confusion if your account has access to multiple scopes. Therefore, it’s highly recommended defining your desired scope.</p>\n</li>\n<li>\n<p>Having a CSV file as an attachment in the HIRO graph. Please see below to create an attachment vertex and load the CSV data.</p>\n</li>\n</ol>\n</div>\n<div class=\"sect2\">\n<h3 id=\"_creating_attachment_vertex\">Creating attachment vertex</h3>\n<div class=\"paragraph\">\n<p>In case you do not have an attachment vertex in the graph yet, a simple curl command is given below. Please refer to <a href=\"https://core.engine.datagroup.de/help/specs/?url=definitions/graph.yaml#/\">HIRO Graph REST API</a> to know more about the API. In the following command replace &lt;TOKEN&gt; and &lt;SCOPE_ID&gt;. In this document we run our requests against the stage graph, replace the url with <a href=\"https://core.engine.datagroup.de/\" class=\"bare\">https://core.engine.datagroup.de/</a> for global graph. When a valid scope and token is used, you are presented with a response. Make a note of \"ogit\\/_id\", this will be used in the steps to follow.</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-bash\" data-lang=\"bash\">curl -k --request POST --url https://eu-stagegraph.almato.ai/api/graph/7.1/new/ogit%2fAttachment --header 'Authorization: Bearer $TOKEN' --header 'Content-Type: application/json' --data '{\"/name\": \"CSV\", \"ogit/_scope\": \"&lt;SCOPE_ID&gt;\"}'</code></pre>\n</div>\n</div>\n</div>\n<div class=\"sect2\">\n<h3 id=\"_load_csv_data_to_the_attachment\">Load CSV data to the attachment</h3>\n<div class=\"paragraph\">\n<p>In this section we load the CSV data into the attachment created in the previous section. In the following curl command replace &lt;ID&gt; with \"ogit\\/_id\" from the previous step. The response is the contentId of the attachment. Please note, maximum size of csv file should not be bigger than maximum size of the vertex.</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-bash\" data-lang=\"bash\">curl --request POST --url https://eu-stagegraph.almato.ai/api/graph/7.1/&lt;ID&gt;/content --header 'Authorization: Bearer $TOKEN' --header 'Content-Type: text/csv'\n--data 'h1,h2,h3,h4\n&gt; 1,2,3,5\n&gt; 6,7,8,9\n&gt; 10,11,12,13'</code></pre>\n</div>\n</div>\n</div>\n</div>\n</div>\n<div class=\"sect1\">\n<h2 id=\"_using_the_action_handler\">Using the Action Handler</h2>\n<div class=\"sectionbody\">\n\n</div>\n</div>\n<div class=\"sect1\">\n<h2 id=\"_parameters_in_the_action_handler\">Parameters in the Action Handler</h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>The table given below consists of parameters that can be used in the KI to achieve the desired structure of JSON.</p>\n</div>\n<table class=\"tableblock frame-all grid-all stretch\">\n<colgroup>\n<col style=\"width: 50%;\">\n<col style=\"width: 50%;\">\n</colgroup>\n<thead>\n<tr>\n<th class=\"tableblock halign-left valign-top\">Parameter</th>\n<th class=\"tableblock halign-left valign-top\">Description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">keys (optional)</p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">Identifier if keys are represented by rows or columns, default being row. Expected values: row or column.</p></td>\n</tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">colOffset (optional)</p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">Offset rows of the table. Entries before the offset are ignored. Default: 0</p></td>\n</tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">rowOffset (optional)</p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">Offset columns of the table. Entries before the offset are ignored. Default: 0</p></td>\n</tr>\n<tr>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">delimiter (optional)</p></td>\n<td class=\"tableblock halign-left valign-top\"><p class=\"tableblock\">Delimiting character. Default:, or Comma</p></td>\n</tr>\n</tbody>\n</table>\n<div class=\"sect2\">\n<h3 id=\"_calling_via_ki\">Calling via KI</h3>\n<div class=\"paragraph\">\n<p>In the following KI example, we use the default parameter values. When an issue with variable <code>ConvertToSpreadsheet</code> and <code>SourceId</code> is created, this KI is triggered and the corresponding CSV is converted to JSON.</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"title\">Sample KI for CSV to JSON conversion</div>\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-bash\" data-lang=\"bash\">on\n  ogit/_id\nwhen\n  ConvertToSpreadsheet\n  SourceId\ndo\n  code: LOCAL::STATUS,\n  body: LOCAL::RESULT = action(\n      capability: \"CSVtoSpreadsheet\",\n      sourceId: SourceId\n  )\n  if LOCAL::STATUS == \"200\" then\n    log(\"SUCCESS: Your CSV is has been formated ${LOCAL::RESULT#result}\")\n    TargetId = \"${LOCAL::RESULT#result['target_id']}\"\n\tdelete(ConvertToSpreadsheet)\n  else\n    log(\"ERROR ${LOCAL::STATUS}: ${LOCAL::RESULT}\")\n  end</code></pre>\n</div>\n</div>\n<div class=\"listingblock\">\n<div class=\"title\">Example of data returned by CSV ActionHandler</div>\n<div class=\"content\">\n<pre>log SUCCESS: Your CSV is has been formated {\"target_id\": \"${TARGET_ID}\"}</pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>You can modify the KI to use column as identifier:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"title\">Sample KI for CSV to JSON conversion with column as identifier</div>\n<div class=\"content\">\n<pre>do\n  code: LOCAL::STATUS,\n  body: LOCAL::RESULT = action(\n      capability: \"CSVtoSpreadsheet\",\n      sourceId: SourceId,\n      keys: \"column\",\n  )</pre>\n</div>\n</div>\n</div>\n<div class=\"sect2\">\n<h3 id=\"_resulting_spreadsheet\">Resulting Spreadsheet</h3>\n<div class=\"paragraph\">\n<p>On successful execution of the KI, you were presented with the <code>TARGET_ID</code> which holds the <code>ogit/_id</code> of the created <code>ogit/Documents/Spreadsheet</code> node.\nThis node holds the JSON fomated CSV.</p>\n</div>\n<table class=\"tableblock frame-all grid-all stretch\">\n<caption class=\"title\">Table 1. JSON structure when the key is set to Row vs Column</caption>\n<colgroup>\n<col style=\"width: 50%;\">\n<col style=\"width: 50%;\">\n</colgroup>\n<tbody>\n<tr>\n<td class=\"tableblock halign-center valign-top\"><div class=\"content\"><div class=\"paragraph\">\n<p>Row</p>\n</div></div></td>\n<td class=\"tableblock halign-left valign-top\"><div class=\"content\"><div class=\"paragraph\">\n<p>Column</p>\n</div></div></td>\n</tr>\n<tr>\n<td class=\"tableblock halign-center valign-top\"><div class=\"content\"><div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-json\" data-lang=\"json\">{\n  \"/h3\": [\n    {\n      \"created\": 1614085834712,\n      \"value\": \"3\",\n      \"key\": 0\n    },\n    {\n      \"created\": 1614085834712,\n      \"value\": \"8\",\n      \"key\": 1\n    },\n    {\n      \"created\": 1614085834712,\n      \"value\": \"12\",\n      \"key\": 2\n    },\n    {\n      \"created\": 1614085834712,\n      \"value\": \"23.0\",\n      \"key\": \"Total\"\n    }\n  ],\n  \"/h4\": [\n    {\n      \"created\": 1614085834712,\n      \"value\": \"5\",\n      \"key\": 0\n    },\n    {\n      \"created\": 1614085834712,\n      \"value\": \"9\",\n      \"key\": 1\n    },\n    {\n      \"created\": 1614085834712,\n      \"value\": \"13\",\n      \"key\": 2\n    },\n    {\n      \"created\": 1614085834712,\n      \"value\": \"27.0\",\n      \"key\": \"Total\"\n    }\n  ],\n  \"/h1\": [\n    {\n      \"created\": 1614085834712,\n      \"value\": \"1\",\n      \"key\": 0\n    },\n    {\n      \"created\": 1614085834712,\n      \"value\": \"6\",\n      \"key\": 1\n    },\n    {\n      \"created\": 1614085834712,\n      \"value\": \"10\",\n      \"key\": 2\n    },\n    {\n      \"created\": 1614085834712,\n      \"value\": \"17.0\",\n      \"key\": \"Total\"\n    }\n  ],\n  \"/h2\": [\n    {\n      \"created\": 1614085834712,\n      \"value\": \"2\",\n      \"key\": 0\n    },\n    {\n      \"created\": 1614085834712,\n      \"value\": \"7\",\n      \"key\": 1\n    },\n    {\n      \"created\": 1614085834712,\n      \"value\": \"11\",\n      \"key\": 2\n    },\n    {\n      \"created\": 1614085834712,\n      \"value\": \"20.0\",\n      \"key\": \"Total\"\n    }\n  ],\n  \"ogit/_type\": \"ogit/Documents/Spreadsheet\"\n}</code></pre>\n</div>\n</div></div></td>\n<td class=\"tableblock halign-left valign-top\"><div class=\"content\"><div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-json\" data-lang=\"json\">{\n  \"ogit/_created-on\": 1614068913491,\n  \"/10\": [\n    {\n      \"created\": 1614068912895,\n      \"value\": \"11\",\n      \"key\": 0\n    },\n    {\n      \"created\": 1614068912895,\n      \"value\": \"12\",\n      \"key\": 1\n    },\n    {\n      \"created\": 1614068912895,\n      \"value\": \"13\",\n      \"key\": 2\n    },\n    {\n      \"created\": 1614068912895,\n      \"value\": \"36.0\",\n      \"key\": \"Total\"\n    }\n  ],\n  \"/6\": [\n    {\n      \"created\": 1614068912895,\n      \"value\": \"7\",\n      \"key\": 0\n    },\n    {\n      \"created\": 1614068912895,\n      \"value\": \"8\",\n      \"key\": 1\n    },\n    {\n      \"created\": 1614068912895,\n      \"value\": \"9\",\n      \"key\": 2\n    },\n    {\n      \"created\": 1614068912895,\n      \"value\": \"24.0\",\n      \"key\": \"Total\"\n    }\n  ],\n  \"/1\": [\n    {\n      \"created\": 1614068912895,\n      \"value\": \"2\",\n      \"key\": 0\n    },\n    {\n      \"created\": 1614068912895,\n      \"value\": \"3\",\n      \"key\": 1\n    },\n    {\n      \"created\": 1614068912895,\n      \"value\": \"5\",\n      \"key\": 2\n    },\n    {\n      \"created\": 1614068912895,\n      \"value\": \"10.0\",\n      \"key\": \"Total\"\n    }\n  ],\n  \"/h1\": [\n    {\n      \"created\": 1614068912895,\n      \"value\": \"h2\",\n      \"key\": 0\n    },\n    {\n      \"created\": 1614068912895,\n      \"value\": \"h3\",\n      \"key\": 1\n    },\n    {\n      \"created\": 1614068912895,\n      \"value\": \"h4\",\n      \"key\": 2\n    },\n    {\n      \"created\": 1614068912895,\n      \"value\": \"NaN\",\n      \"key\": \"Total\"\n    }\n  ],\n  \"ogit/_type\": \"ogit/Documents/Spreadsheet\"\n}</code></pre>\n</div>\n</div></div></td>\n</tr>\n</tbody>\n</table>\n</div>\n</div>\n</div>","document":{"main":"CSV ActionHandler User Guide","title":"CSV ActionHandler User Guide","subtitle":""},"fields":{"toc":true,"location":["documentation","integration","CSV","CSV_AH"]}},"sidebarYaml":{"id":"6d066bdd-c982-5a69-b909-a31e6fc044e0","showIndex":null}},"pageContext":{"id":"ec5bb116-6274-52c6-9405-b423329014d4","parent":"documentation"}},"staticQueryHashes":["1010459453","1010459453","2356112386","2356112386","2603905930","2603905930","3026652197","3026652197","3167850324","3167850324","63159454","63159454"]}