Support » Plugin: Bible Text » Updating for v3 of ESV API?

  • Hi Mark,

    Just found out that my church clients who are using your plugin are getting errors from ESV rather than the biblical texts.

    It looks like ESV or Crossway has deprecated v2.

    Are you planning on updating the plugin to be compatible with v3? Or should I look into this myself?

    Thanks for a great plugin!
    John

Viewing 6 replies - 1 through 6 (of 6 total)
  • I just ran into the same issue. I poked around in the new API and came up with the following quick hack. You’ll need to get an API key from http://api.esv.org, then replace the mbbt_add_esv_text function with the code below.

    //Returns ESV text
    function mbbt_add_esv_text ($reference, $heading) {
    		$esv_url = 'http://api.esv.org/v3/passage/html/?q='.urlencode($reference).'&include-headings=false&include-footnotes=false';
        if ($heading === FALSE || strtolower($heading) == 'span')
            $esv_url .= '&include-passage-references=false&include_audio_link=false&include-first-verse-numbers=false';
    
    		$esv_args = array(
    			'headers' => array (
    				'Authorization' => 'Token XXXXXXXXXXXXXXXXXXX'
    			)
    		);
    
        $response = json_decode(wp_remote_retrieve_body(wp_remote_get($esv_url, $esv_args)));
    		return $response->passages[0];
    }

    Thanks Rob. Were they pretty quick at approving the API app? I made your changes and nothing is showing up, but I am assuming that is because they haven’t approved it yet.

    I was approved right away, but I work for a church as well. If your app is a commercial app, they may review it manually.

    Hi Rob,

    Thanks for your “quick hack”. I uncovered the same issue as you, realized I needed a v3 API key and how to properly format the Request URL; but, I was going crazy trying to figure out how to pass the API key. Your example, was EXACTLY what I needed. As a return gift to you, if you have not already done so, your “quick hack” inadvertently “breaks” the ability to pass multiple (or non-contiguous) passages in the search request (e.g., Romans 8:28,31 will only return Romans 8:28, and Matthew 28:18-20; Acts 1:8 will only return Matthew 28:18-20 – in these two instances, the non-contiguous passages, Romans 31 and Acts 1:8, although returned by the Request URL, are ignored by the plugin function because you are only returning the first passage returned: $response->passages[0]).

    The following modification to your “quick hack” resolves this issue and restores full functionality to the routine. Also, I added more options settings based on the API documentation. You may wish to modify those as you see fit. One note: ESV’s options has a bug where the “attach-audio-link-to” option, which can be set to either “passage” or “heading”, according to the documentation, seems to only recognize “passage” and yet it places the link next to the heading (go figure). I do not have time to chase that rabit any longer. Just thought I would pass it along.

    Thanks for pointing me in the right direction! May God richly bless you exceedingly beyond your ability to measure.

    Bro. Chris
    Saved by Grace Ministries
    http://SavedByGrace.net

    //Returns ESV text
    function mbbt_add_esv_text ($reference, $heading) {
    		$esv_url = 'https://api.esv.org/v3/passage/html/?q='.urlencode($reference).'&inline-styles=true&include-passage-references=true&include-chapter-numbers=true&include-first-verse-numbers=true&include-verse-numbers=true&include-footnotes=false&include-audio-link=true&attach-audio-link-to=passage&include-short-copyright=false';
        if ($heading === FALSE || strtolower($heading) == 'span')
            $esv_url .= '&include-passage-references=false&include_audio_link=false&include-first-verse-numbers=false';
    
    		$esv_args = array(
    			'headers' => array (
    				'Authorization' => 'Token XXXXXXXXXXXXXXXXXXXX'
    			)
    		);
    
        $response = json_decode(wp_remote_retrieve_body(wp_remote_get($esv_url, $esv_args)));
    	$output = '';
    	$passages = array();
    	$passages = $response->passages;
    	foreach ($passages as $passage) {
    		$output .= $passage;
    	}
    		return $output;
    }

    Hi,

    I updated to the V3 API and it’s been working fine for the past few months. However, this week I tried to access a scripture and in the returned response all of the fields except query were empty. Here is the JSON returned for phi 2:4-5:
    {“query”:”‘phil 2:4-5′”,”canonical”:””,”parsed”:[],”passage_meta”:[],”passages”:[]}

    When I request this from the API V3 page “demo”, the correct information is returned. This seems really odd to me because I am getting a response and a status code of 200. So it is getting my request, it understands what I’m looking for, and it is successfully returning a response, but it isn’t returning the content.

    Any idea what’s happening?

    Thanks.

    Gary

    Okay, I found out it was a coding error, two actually, but I had single quotes around the query parm, which I think is why it wasn’t working. Glad I added the URL to the debug output before I tried to ask Crossway about it!

    Thanks.

    Gary

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Updating for v3 of ESV API?’ is closed to new replies.