First we have to check, how we can get access to the JSON-data the API offers: Every APIs has it’s indivual expectaion. With one API a simple URL is enough, others expect data in the header or other parts of the http-protocol. You can do all steps by your own – if you need help: When buying the PRO-version basic help is included. For more complex projects I do work on an hourly based rate.
Recommended is to try services like apitester.com or www.getpostman.com: What you might need for getting JSON there is to understand, how the authentication of the API works. See the API manual for that (if needed).
- Simple 1st test
You can use the URL (e. g. URL_FROM_API) for ypour API in an JCI-shortcode and see what is happening (JSON-Content-Importer plugin free and / or pro installed and active, delete any linefeeds in the shortcode!!)
[jsoncontentimporter debugmode=10 url=URL_FROM_API]test[/jsoncontentimporter]
or with the PRO-version
[jsoncontentimporterpro debugmode=10 url=URL_FROM_API]test[/jsoncontentimporterpro]
Put this shortcode on a ordinary wordpress-page or -post and do a preview.
In the best case you see some debug-info incl. JSON-data and as result “test”. Then you can proceed to Step 2: Convert JSON to HTML.
If you do not get JSON or a error message is part of the debug-messages: The API, URL_FROM_API is expecttin something more or your server has a missing feature.
Let’s debug this:
- Timeout-Error: It takes too long to get an answer from the API-Server. After default 5 sec a WordPress-sErver stops trying. By adding “urlgettimeout=NUMBER” you can increas the timeout-time to “NUMBER” seconds
- Authentication with free JCI-plugin: See the Options of the plugin at “API-Request: If needed, send Authentication-Info or an Browser-Useragent”: You can send a “default Useragent” (some API needs that, as they then think a ordinary browser is requesting) and “Authorization: Bearer accesskey” / “Authorization: accesskey”. See the manual of the API, if the API is ok with that and how you get a (static) value for “accesskey”.
- Authentication with PRO JCI-plugin: With the PRO plugin you can handle almost any authentication, esp. those in CURL-Syntax. For that set up a JCI-Template:
- Template-Text: Leave it like it is
- Unique template-Name: Give a name, e. g. “test”
- Debug mode: Select radio for “debugmode ON (display more debug-infos…)
- URL: Insert your API-URL URL_FROM_API
- Method: Select CURL-GET (if API-manual tells you, that you need POST select CURL-POST). If you see an errormessage like “invalid method” etc. you can tzry the other settings.
- Curloptions: Here you can define the CURL-request in detail. See https://www.php.net/manual/de/function.curl-setopt.php for what Parameter CURL can process.
Often used are those:- CURLOPT_HTTPAUTH=CURLAUTH_BASIC
> set basic auth. - CURLOPT_TIMEOUT=30
> set timeout in sec - CURLOPT_HTTPHEADER=accept:application/json##Authorization:Bearer whatever##a:{{urlparam.VAR1}}##c:d;CURLOPT_POSTFIELDS=e:f##{“g”:”h”}##i:j
> set http-header - CURLOPT_SSL_VERIFYHOST=false;CURLOPT_SSL_VERIFYPEER=false
> deactivate check of SSL-/TCL-certificate (if you Worpdres-Server or the API-Server have problem with those certificates) - CURLOPT_POSTFIELDS=…
> If this is set to an valid JSON-String, a string is sent to the API (then “application/x-www-form-urlencoded”). It depends on the API what way is ok.
- CURLOPT_HTTPAUTH=CURLAUTH_BASIC
- Postpayload: Needed if the API expects some more input with a POST-reqest
- Timeout: You might increase that if needed
Then use this shortcode (name of template e. g. “test”) and try a preview:
[jsoncontentimporterpro nameoftemplate=test]
Keep in mind that the 2 plugins use different shortcodes, the two plugins are completely independent!
Version | SHORTCODENAME |
---|---|
PRO-Version | jsoncontentimporterpro |
Free Version | jsoncontentimporter |