Wordpress在调用函数后添加过滤器

I have a function where I make a call to API and get a lot of data. This API returns me also meta description.

I'm calling this function api_call() in my template.php

I'm using YoastSEO plugin for SEO. I have a hook, where I can add meta description. The problem is how i can pass $metadescriptionfromAPI to that hook:

function filter_wpseo_metadesc( $metadesc ) {

  if (($metadesc == '') || (!isset($metadesc))) {
    $metadesc = $metadescriptionfromAPI; /* This goes from API */
  }
    return $metadesc;

};

add_filter( 'wpseo_metadesc', 'filter_wpseo_metadesc');

I tried to use global $metadescriptionfromAPI but it didn't work.

I think it's because $metadescriptionfromAPI variable is empty when i'm using add_filter. How can I pass $metadescriptionfromAPI to that add_filter?