# Working with data FAQs

Common questions Tray customers ask about what you can do with data that is received from and sent to third party services

## How do I insert output data into plain text? (Interpolation mode)

### Intro

Interpolation mode allows you to insert data returned by connectors into plain text fields in subsequent connectors.

### Set data type of input to string

First, make sure that the datatype of your input is a string:
![select string](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/1aavSQGqV2xUfZ1msuZRLG_select_string.png)

### Method 1 - copy / pasting the jsonpath

### Method 2 - using the connector snake

## How do I insert output data into code blocks?

### Intro

Interpolating data into a code block requires a slightly different method

### Identify code block

Ever try using a shortcut to interpolate and it did not work? 
![its a code block](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/6meFfX6IaW9oCjtm35tuY5_its_a_code_block.png)

### Insert jsonpath

To reference a jsonpath in a **code block**, you will need to use templating.
Write out the jsonpath inside of curly braces `\{ \}` to dynamically reference that JSON path. For example, here to reference the trigger id you would write out `\{$.steps.object-helpers-1.result.trigger_id\}.`
![templated example](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/6iW98lYiK4tBbpYFeFCaMS_templated_example.png)

## How do I access the data from error messages?

### Intro

\*\* \*\*How to access error messages from a connector when using manual error handling

### Choose error handling method

After you choose Manual Error Handling you will see a default and error branch coming from your connector step.
So you can then, for example, send an alerting email (this is of course a very simple example, and you could use the error branch to build a sophisticated alternative route for your workflow):
![errors](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/2jDK8B8JaCDZ6UL4TYDddQ_errors.png)
The above example shows how to compile a simple email (this could also be a message to a Slack channel or any other option you might want to implement) which makes use of the error message from the output of the errored step.

### Referencing the error

When referencing the error message from the step, the error object needs to be accessed using the following format `$.errors.<step-name>.message`
In the above example, the error response from the API is being accessed using the following string: `$.errors.http-client-1.response.body`

## Can I loop through config data?

### Intro

When using [config data](https://tray.io/documentation/embedded/core-topics/config-data/setting-config-data/) in Tray, it may sometimes be necessary for your use case to loop through an array of values associated with one config property. To do this, you’ll need to follow the below steps:

### 1 - Create config property

Navigate to the meatballs menu (), select **Config data,** and enter a property name. 

![add-config-property](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/4FZVoGlGeoejqFI1iYdELd_add-config-property.png)

### 2 - Edit config property

Click the pencil icon () to begin editing your property, and change the data type of the field from a string, represented by and A (), to an array, represented by square brackets ().
Click **Add to \&#123;{property\_name\&#125;}**, and another string field will appear. Change this field to an object, represented by a table icon (). This is your first object in the array.
Click \*\*Add to property 0 \*\*and enter a name. This is the first key in the object. 
In the string field below the property you just created, enter the value:
![enter-property-value](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/3Nw9Id319BUyoHWAWvXyVV_enter-property-value.png)

### 3 - Add more properties or objects

You can continue adding properties (keys), or you can scroll slightly further down and add additional objects by clicking \*\*Add to \&#123;{property\_name\&#125;} \*\*again and follow the steps above to create as many objects with as many key value pairs as needed.
![add-objects](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/vPs8buJxeUIyElSKrbYD2_add-objects.png)

### 4 - Change List in Loop Connector

To loop through the objects in your config data, you will first change the **List** parameter in the **Loop Connector** to **Jsonpath**, and set the path to **$.config.\&#123;{property\_name\&#125;}**. This will loop through each object you created.
![change-list-in-loop-connector-2](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/1ks14nyKqlMuwGBQMrY3Fw_change-list-in-loop-connector-2.png)

## What is Unix time?

### Answer

Unix time is an integer that represents the number of seconds that have passed since January 1st, 1970 UTC (Coordinated Universal Time). It's a way to track time as a running total of seconds.
Here's a handy table with some conversions:

| **What we use**                                                                                                                                                      | **Time in seconds** |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- |
| 1 Hour                                                                                                                                                               | 3600 Seconds        |
| 1 Day                                                                                                                                                                | 86400 Seconds       |
| 1 Week                                                                                                                                                               | 604800 Seconds      |
| 1 Month (30.44 days)                                                                                                                                                 | 2629743 Seconds     |
| 1 Year (365.24 days)                                                                                                                                                 | 31556926 Seconds    |
| You can use a number of online calculators to convert human-readable dates into Unix time. [Unix Time Stamp ](https://www.unixtimestamp.com/index.php)is a good one. |                     |

##

## What are the data limits for the File Helpers connector?

### Explanation of File Helpers data limits

The File Helpers connector has two main functionalities;

* Reading a file
* Creating a file
  **Reading a file**
  The maximum file size is 6MB.
  \*The general limit for passing data between connector steps is 1MB. Passing data larger than 1MB may cause issues. More information in the [data payload limits](https://tray.io/documentation/platform/connectors/technical-limits-and-retry-info/#data-payload-limits) documentation. 
  **Creating a file**
  When creating a file from a URL, the maximum file size is 5GB. This is the optimum file maximum however, there are multiple factors that may affect file creation such as file size, file type, download location, 3rd party speeds etc. 
  For example, if a 3rd party's file serving speed is quite slow the connector may time out if the file download takes longer than 15 minutes. 

## Should I use the CSV Reader or CSV Editor?

### First considerations

You may have already read the following from the docs for our CSV tools:
![csv-reader-editor-from-docs](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/2cvzny5Fvc3oonREOOsoV_csv-reader-editor-from-docs.png)

### Further points for consideration

Still unsure which is best for you?
Please consider the following as well:

* The CSV *Reader* is most useful for CSVs that are \*\*\*hundreds to millions of rows long \***("very large CSV files")**. \*\*
  * As detailed in the [docs](https://tray.ai/documentation/connectors/core/csv-reader/), the \*Reader \*works through pagination with asynchronous queries, so you would need to build in a structure in your workflow to poll the job until your query returns.
  * In order to get that amount of information quickly, the CSV reader can't rely on the line-by-line method the CSV editor uses when retrieving information, so it uses an asynchronous method to retrieve data, in much the same way a database would retrieve information.
* The CSV *Editor *is typically the ***simplest to use***** \*\*for CSV files that are not too large
  * You can use the '**Get Rows'**\*\*\* \*\*\*operation to read a file without any pagination. 
* The CSV \*Editor \*can experience throttling during times of high usage across all users, as explained

## What is the CSV Reader NextToken?

### The 'Get Query Results' operation

If you choose to use the \*Reader, \*this token is used for paginating results, where you would need to continue getting results using the "**Get query Results**" operation:
![csv-get-query-results-next-token](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/22ytd0PhmUvLO4fGO8JSDK_csv-get-query-results-next-token.png)

### Get QueryExecutionId and NextToken

You'll need to use the **QueryExecutionId** and \*\*NextToken \*\*from the output of your CSV reader as inputs above, and include a failsafe/check that stops the loop when there are no more results to retrieve. We would recommend using [callable workflows](https://tray.ai/documentation/connectors/triggers/callable-trigger/) for this process 
![csv-reader-use-token](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/6ElEo3fnkpO8mfFGg0bwLz_csv-reader-use-token.png)

## Can I import Javascript/Python libraries into the Script connectors?

### Answer

No, import operations are not supported in the Script connectors.
Tray JS Script connector does have 2 Javascript libraries currently built-in:
[Lodash](https://lodash.com/)
[Moment](https://momentjs.com/)
You can use any of the operations in these libraries without an 'import' statement.
The Python script connector includes **all default** libraries. However, we do not support custom/ad-hoc ones created by the user.

## How do I convert JSON to XML (and vice versa)?

### Converting JSON to XML

1. Add the XML Helper connector
2. Set operation to **'Convert JSON to XML'**
3. Either paste the JSON to be converted into the text box or use the connector snake to input the JSON from a previous step
   ![JSON2XML](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/5sMDaKkrHYJrEoISdZ1JVQ_JSON2XML.png)

### Converting XML to JSON

1. Add the XML Helper connector
2. Set operation to **'Convert XML to JSON'**
3. Either paste the XML to be converted into the text box or use the connector snake to input the XML from a previous step
   ![XML2JSON](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/Zj7agRyOy6wZCoKGDoSPj_XML2JSON.png)

## Can I send a file with the HTTP Client?

### The form-data option

1. Add the HTTP Client connector to the workflow and set the method to POST
2. Set the Body Type to 'form-data'
3. Use the connector snake or JSON path to link the file object to the form-data parameter
   ![form-data](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/bh3JxZgTryezipRRzNoeN_form-data.png)

### The binary option

*Using the binary body type requires the use of the File Helper connector to add the 'expires' parameter to the file object*

1. Add the File Helper connector before your HTTP Client connector
2. Set the File Helper operation to 'Create file from content'
3. Link the Content parameter to the file object
4. Add the HTTP Client connector to the workflow and set the method to POST
5. Set the Body Type to binary
6. Use the connector snake or JSON path to link the file object to the binary parameter
   ![file-helper](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/4Ms5D6AHkGLmc84oFmrJPf_file-helper.png)

## "Data is too large to be displayed". How to visualise the incoming data in such a case?

### Answer

Some service connectors and HTTP client GET method to retrieve data from a system might result in a huge volume of data that can't be displayed in the logs. The logs show a message: *"Data is too large to be displayed. However, it is still available to subsequent steps."*
![TooLargeData](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/3mWnWJAl55tVrxURgpXcHO_TooLargeData.png)
You would need to see the schema in order to process the data in further steps. For this, you may:

### Slice the response

If you know the API returns a JSON response, you can use the slice function from the Script connector and get the first 5 elements from the output of this step. View the schema in the logs and plan further steps.
![scriptSlice](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/4Vij6MVUQUT77GhMsoARPL_scriptSlice.png)

### Write response to a file

A better and cleaner way would be to write the output data into a file using **'Create file from content'** operation of [File helpers](https://tray.ai/documentation/connectors/helper/file-helper) connector.
![fileHelpers](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/Zpl7E4sNW9KUC0w9j4DJL_fileHelpers.png)
You can get the file URL after running the workflow in the logs. Open the URL in the browser, check the content and plan further steps.
![fileHelpersUrl](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/fdOfQ1Po8hslhFWb3P2Uj_fileHelpersUrl.png)

## How do I fix my output?

### Step 1

This is the first step
![Screen Shot 2022-09-26 at 4.17.19 pm](https://tray.ai/documentation/images/help/frequently-asked-questions/working-with-data-faqs/3gWD3wcZKCYt8zivGXs54Z_Screen%20Shot%202022-09-26%20at%204.17.19%20pm.png)
