Consuming an API and getting the response

I’m sorry for the pretty newbie question (but that’s what I am), but I wonder it there is a guide or something easy documented about how to consume a webservice and getting the response (json format).

I need to call this webservice and navigate throught the returned json file.

Thanks in advance

Eg:

$request = Remote::get('https://api.song.link/v1-alpha.1/links?url=spotify%3Atrack%3A0Jcij1eWd5bDMU5iPbxe2i&userCountry=US');
$results = null;
if ($request->code() === 200) {
  $results = json_decode($request->content, true);
}
dump($results);
1 Like

Thank you. I checked the kirby site before asking here on this forum, but it seems I searched for the wrong terms :frowning:

Now I’m able to consume the API. I’d like to save the result instead of getting the result every time. Is it savy to save the result as a serialized array using a hidden field type?

Yes, you can do that, or store the json string

Store the json as an atteched file? Just like if it was an image?

That would be an option, but you might as well store it in the content file. Or store it in the cache, depending on use case

ok. thank you.