<@U04SE163WC8> I have an API response that returns...
# ask-ai
s
@kapa.ai I have an API response that returns the standard response, body, headers. The body only contains an array and using the record selector with a field path of "body" says "No records could be extracted from the response". What can I do to have the array/list stored as a single column table?
u
If your API response's body contains an array and you want to store it as a single column table, you can use the record selector with an empty field path. This will select the whole response as a record. Here is how you can define it:
Copy code
yaml selector:     extractor:       field_path: []
This will treat the root of the response as a record. If the root of the response is an array, it will extract the records from it. If the root of the response is a JSON object representing a single record, it will extract the record and wrap it in an array. However, please note that not all destinations can natively handle
array
fields. If your destination cannot handle
array
fields, the destination connector is free to simply JSON-serialize the array back to a string when pushing data into the end platform. This means that the array will be stored as a string in a single column of your table. For more information, you can refer to the following documentation: - [Record Selector - Common Recipes](https://docs.airbyte.com/connector-development/config-based/understanding-the-yaml-file/record-selector#common-recipes) - [Unsupported Types](https://docs.airbyte.com/understanding-airbyte/supported-data-types#unsupported-types)
s
@kapa.ai leaving the field path in the record selector empty gives this error "ValueError: dictionary update sequence element #0 has length 1; 2 is required"
u
A message from kapa.ai
u
The error message you're seeing, "ValueError: dictionary update sequence element #0 has length 1; 2 is required", is a common Python error that occurs when you're trying to convert a sequence into a dictionary, but the sequence elements don't have the correct length. In the context of Airbyte's record selector, this error might occur if the response from the API is not a JSON object or an array of JSON objects. The record selector expects to work with JSON objects, where each object is a dictionary-like structure with key-value pairs. If you're seeing this error, it's likely that the API response is not in the expected format. You might need to adjust the API request or the record selector configuration to ensure that the response is a JSON object or an array of JSON objects. If you're still having trouble, it would be helpful to look at the exact API response and the record selector configuration. You can also refer to the [Airbyte documentation on the record selector](https://docs.airbyte.com/connector-development/config-based/understanding-the-yaml-file/record-selector) for more information on how to configure the record selector.
s
@kapa.ai This is the exact API response (with header values removed): { "status": 200, "body": [ "NA1_1234567890", "NA1_2345678901", "NA1_3456789012", "NA1_4567890123", "NA1_5678901234" ], "headers": { etc. } }
u
A message from kapa.ai
u
The API response you provided is a JSON object that contains a
status
,
body
, and
headers
. The
body
is an array of strings. If you want to store the
body
array as a single column table, you can use the
Iterable
response format in the Airbyte connector builder. This response format is used for API response bodies that are text containing strings separated by newlines. By convention, the connector will wrap each of these strings in a JSON object under a
record
key. Here is how you can define it:
Copy code
yaml response_format:   type: "iterable"
This will treat each string in the
body
array as a separate record. Each record will be a JSON object with a single property
record
that contains the string. For more information, you can refer to the following documentation: - [Iterable Response Format](https://docs.airbyte.com/connector-development/connector-builder-ui/record-processing#iterable) Please note that this will work if your destination can handle
array
fields. If your destination cannot handle
array
fields, the destination connector is free to simply JSON-serialize the array back to a string when pushing data into the end platform. This means that the array will be stored as a string in a single column of your table.
s
@kapa.ai - I still receive the error "ValueError: dictionary update sequence element #0 has length 1; 2 is required" when adding the following under "Additional fields" in the low-code builder:
Copy code
response_format:
  type: "iterable"
u
A message from kapa.ai
u
I'm sorry for the confusion. The
iterable
response format is used for API response bodies that are text containing strings separated by newlines. In your case, the
body
field is an array of strings, which is not the same as a text containing strings separated by newlines. The error you're seeing, "ValueError: dictionary update sequence element #0 has length 1; 2 is required", is a Python error that occurs when you're trying to convert a sequence into a dictionary, but the sequence elements don't have the correct length. This error is likely occurring because the
iterable
response format is expecting a text containing strings separated by newlines, but it's receiving an array of strings instead. Unfortunately, based on the information provided in the knowledge sources, it seems that Airbyte's low-code connector builder does not currently support handling an array of strings in the way you're trying to do. You might need to write a custom connector to handle this specific use case. For more information on how to write a custom connector, you can refer to the [Airbyte documentation on building new connectors](https://docs.airbyte.io/connector-development).
a
@Sam Mullican I'm having the same problem, could you fix it?
s
@Adolfo Bellani I couldn't, but I was doing it more as a test of Riot's API than something I actually needed to build. When I have some more time in the future I'll probably get back to it to continue playing around. In the meantime if you figure something out let me know too if you don't mind :D
a
I could get all the data in only one register. The problema is that the record is a string