Bringing data from external REST API into Looper

I’ve read through all the documentation and watched all the videos on the YT channel, but can’t seem to find an answer to my issue.

I’m setting up a custom looper to display data from an external REST API. I have the following filter written to fetch the data:

add_filter( 'cs_looper_custom_get_publications', function( $result ) {

  $apiUrl = "https://example.com/rest-api/publications/";

  $ch = curl_init();

  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Token 123456789', 'Accept: application/json'));
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_URL, $apiUrl);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_VERBOSE, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

  $response = curl_exec($ch);

  curl_close($ch);

  $data = json_decode($response);
  $results = $data->results;

  $json_results = json_encode($results);

  return $json_results;

});

Which works, grabs all my data just fine. $json_results looks like this:

[
  {
    "id": 14372,
    "headline": "Sample",
    "tags": [],
    "categories": [],
    "publish": true
  },
  {
    "id": 14372,
    "headline": "Demo",
    "tags": [],
    "categories": [],
    "publish": true
  },
  {
    "id": 14372,
    "headline": "Test",
    "tags": [],
    "categories": [],
    "publish": true
  }
]

And I have the provider/consumer set up:
Screen Shot 2021-03-23 at 5.05.19 PM
Screen Shot 2021-03-23 at 5.06.00 PM

But the looper doesn’t output anything. I can paste the same block of JSON into a looper and it works fine:

What am I doing wrong here? Is there some documentation somewhere I should be looking at? Thanks in advance!

Hello @liquidedge,

Thanks for writing to us.

Please have a look at our video doc for the JSON type looper and you can also check out our documentation as well to learn more about looper provider types.


Hope it helps
Thanks

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.