Print

PRO: Data-Access

Requesting data with a http-request from an URL is the basic 1st step the JCI Plugins do. The JCI PRO Plugin is very flexible in doing this.

Setup a http-request means:

  • Method:
    There are
    How is the request done? Check the API what method GET / POST / PUT is expected. Then usually the CURL-variant is working. If not you may try the other methods.
    • GET:
      • CURL-GET
      • WP-GET
      • PHP-RAWGET
    • POST
      • CURL-POST
      • WP-POST
      • PHP-RAWPOST
    • PUT
      • CURL-PUT

By “Curloptions” in the JCI PRO Template a CURL-Request can be build for any needs.

  • Header:
    PHP-RAW and WP send fixed headers. CURL is very flexible here.
  • Payload:
    Additional Info when using POST
  • Timeout:
    Who many seconds for loading url till timeout?
  • Cachetime:
    Set the cachetime for this URL to n seconds, regardless of the settings in the plugin-option, even when caching is switched off there.

Authentication: API-Keys, oAuth2 etc.

Many APIs require additional info about the asking user. Usual ways are (see the manual of the API you want to ask what it is expecting):

  • API-Key as GET-Parameter:
    Add to the API-URL something like ...&apikey=CODE_YOU_GOT_WHEN_REGISTERING_TO_THE_API
  • Sending the API-Key in the request-header, see the API-manual:
    Usa a JCI-Template and add at CURLOPTIONS something like
    CURLOPT_HTTPHEADER=apikey:CODE_YOU_GOT_WHEN_REGISTERING_TO_THE_API
    or
    CURLOPT_POSTFIELDS=whatever=whatever_credentials&id=CODE_YOU_GOT_WHEN_REGISTERING_TO_THE_API
  • oAuth2:
    A very common way is sending authentication-data (somehow a username and password) to the API and the APIs answers with a Token. This Token is valid for some time and has to be sent for the real API-request about data. See here how this is done:
    Get TokenGet Data with the Token
  • There are many more ways API checking the Authentication

Result of the request: Answer of the API

Depending on the API the result of the request is some data, usally text-data formatted as JSON, XML, CSV…

Handling XML and CSV

With the Shortcode-Options
inputtype=xml or =csv

you can convert XML / CSV into JSON.

Was this article helpful?
0 out Of 5 Stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
5
How can we improve this article?
Please submit the reason for your vote so that we can improve the article.
On this page: