Title: ADS API has changed
Last modified: September 12, 2019

---

# ADS API has changed

 *  [cburns1](https://wordpress.org/support/users/cburns1/)
 * (@cburns1)
 * [6 years, 9 months ago](https://wordpress.org/support/topic/ads-api-has-changed/)
 * Hi.
 * Now that the API for NASA/ADS has changed, this plugin will no longer work. I’ve
   managed to hack the wp_nasaads_query_importer_get_xml() function to use the new
   API and it works! I’m including this updated code below for what it’s worth. 
   To authenticate with the new API, you need to login to ADS and generate a key
   as outlined here:
    [https://github.com/adsabs/adsabs-dev-api#access](https://github.com/adsabs/adsabs-dev-api#access)
   I guess that should be a new parameter in the admin settings or the ADS token.
 * The query_url parameter now needs to use the new ADS library URL scheme. For 
   example, here’s my new token:
 * [wp_nasaads_query_importer_full ads_query_url=https://api.adsabs.harvard.edu/
   v1/biblib/libraries/3RlqL8kxQm-VQE4KaLpMXQ?rows=500 highlight_author=Burns max_num_authors
   =4 link_on_field=title omit_bibcode=True]
 * Note that you need the “rows=500” at the end of the url, or it defaults to only
   20 entries.
 * Chris
 *     ```
       //New function that extracts the XML for the ADS query
       // The API has changed:  we now need to extract a list of bibcodes from the
       // library, then export them to the refxml format
       function new_wp_nasaads_query_importer_get_xml($query_url)
       {
          //I format the query to ADS
          $query_url = wp_nasaads_query_importer_buld_ads_url($query_url);
   
          // Authentication is now done through an API token
          $token = "<INSERT ADS KEY HERE>";
          $token = "Bearer " . $token;
   
          $bibcodes = wp_remote_get(html_entity_decode($query_url),
          array(
             "user-agent"=>"Mozilla/5.0 (WP NASA/ADS Query Importer - WordPress Plugin)",
             "timeout"=>60,
             "headers"=>array("Authorization"=>$token)));
   
          //and I check that the request was successful (if it's an array)
          if (! is_array($bibcodes) )
             return FALSE;
   
          // The return body is JSON, so decode that and get the "documents"
          $bibcodes = json_decode($bibcodes["body"]);
          $bibcodes = $bibcodes->documents;
   
          // Now we need to export as XML. Use POST and it needs list of bibcodes
          // in JSON format
          $urlbase = "https://api.adsabs.harvard.edu/v1/export/refxml";
          $body = json_encode(array("bibcode"=>$bibcodes));
   
          $response = wp_remote_post(html_entity_decode($urlbase),
             array(
                "user-agent"=>"Mozilla/5.0 (WP NASA/ADS Query Importer - WordPress Plugin)",
                "timeout"=>60,
                "headers"=>array(
                   "Authorization"=>$token,
                   "Content-Type"=>"application/json",
                   "Content-Length"=>strlen($body)
                ),
                "body"=>$body
             )
          );
   
          // if successful, decode the body (JSON) and extract the "export"ed data
          if ( is_wp_error($response) )
             return FALSE;
          else
             return json_decode($response['body'])->export;
   
       }
       ```
   
    -  This topic was modified 6 years, 9 months ago by [cburns1](https://wordpress.org/support/users/cburns1/).

The topic ‘ADS API has changed’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-nasaads-query-importer.svg)
 * [WP Nasa/ADS Query Importer](https://wordpress.org/plugins/wp-nasaads-query-importer/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-nasaads-query-importer/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-nasaads-query-importer/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-nasaads-query-importer/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-nasaads-query-importer/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-nasaads-query-importer/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [cburns1](https://wordpress.org/support/users/cburns1/)
 * Last activity: [6 years, 9 months ago](https://wordpress.org/support/topic/ads-api-has-changed/)
 * Status: not resolved