Working with external API response data

Hi,

I wonder if there are any docs/videos on Themeco resources which describe possible manipulations with the data received from an external API. Are there any basics, like swapping the data received from ascending to descending order, etc.? Should that be executed by using TWIG?

Hi John,

Thanks for reaching out.
A few guidelines are already available in our online documentation. Please find them below:

  1. https://theme.co/docs/external-api-developers
  2. https://theme.co/docs/external-api-integration
  3. https://theme.co/docs/twig
  4. https://theme.co/docs/twig-api

Hope it helps.
Thanks

Thanks @tristup,

I have checked the references but still have a challenge with basic sorting of the data.

Here is an example:

{% for i in [ looper.item.Dates ] | reverse %}
	{{ i }}
{% endfor %}

Or this:

{% set data = [ looper.field({"key":"Dates"}) ] %}
{% for dates in data|reverse %}
	{{ dates }}
{% endfor %}

The array still displays dates in chronological order, from earliest to most recent, as received from the API response.

Since you are wrapping your data in an array via [ looper.field({"key":"Dates"}) ] you will only ever reverse a one element array.

To me it sounds like you want to do looper.field({"key":"Dates"}) | reverse instead. Although I’m not sure if Dates is an array.

If the above doesn’t help, when you do {{ looper.field({"key":"Dates"}) | json_encode }} what do you see?

Hi @charlie,

Yes, I want to revert all instances of the looped data inside the array into the opposite order. So instead of 0, 1, 2, 3, 4, 5 that would be 5, 4, 3, 2, 1, 0. But with different dates and date ranges (values) instead of the numbers.
I will also need to do the same with other arrays inside API response, which might have text or boolean values instead. In other words, if we were to work with an Excel table, we would need to revert the order of all rows from A…Z to Z…A in our output.

Current A…Z output for Dates array is the following:

Using looper.field({"key":"Dates"}) | reverse does not return anything.

The output of the {{ looper.field({"key":"Dates"}) | json_encode }} is the following:

Request to the API endpoint is in Raw format.