curloptions, urladdparam & twig / API: planyo.com

API: planyo.com is a swiss web service for managing reservations


Access to the API: The API expects a GET request with a username-password-pair. The special thing is, that together with the username and password, the current timestamp has to be sent, and the whole thing has to be base64-encoded. Also, the URL can have date/time information: If you want to ask the API for all reservations from now back 14 days, the timestamp has to be calculated dynamically.


This can be done in this way:
Put twig-code into the shortcode-parameters urladdparam and curl options:

urladdparam=’&start_time={{“now”| date(“U”)}}&end_time={{“-14days” | date(“U”)}}’
curloptions=’CURLOPT_USERPWD={{ (“username” ~ (“now”| date(“U”)) ~”password”) | base64encode }}’

The plugin executes twig on the urladdparam-value: E.g. ‘{{“now”| date(“U”)}}’ stands for the current timestamp.
The result of the twig execution is added to the URL for asking the API.


Example:

[jsoncontentimporterpro url=https://www.planyo.com/rest/?site_id=3...&sort=&detail_level=4&user_id=&user_email=SOME_MAILADRESS&required_status=&excluded_status=&page=&api_key=d....&method=list_reservations debugmode=10 urladdparam='&start_time={{"now"| date("U")}}&end_time={{"-14days" | date("U")}}' method=curlget curloptions='CURLOPT_USERPWD={{ ("username" ~ ("now"| date("U")) ~"password") | base64encode }}']
{% for d in data.results %}
name: {{d.name}}, reservation_id: {{d.reservation_id}}
{% endfor %}
[/jsoncontentimporterpro]