Hello API

API test1001

This is the first time I build a reporting tool for demonstration purpose.

What this API does, is allowing a user to enter a Yahoo finance ticker and e-mail address, to then by e-mail receive a PDF-report about the Yahoo Finance ticker entered.

If you got the API password, then you may follow this link to test this API.

Issues when building this API

The easy and fun part, was to write the Rmarkdown script. The most tricky parts in building this API was to

  • compile the Rmarkdown script without errors, and then to
  • attach an image and an pdf-file into an e-mail to send to the vistor.

The tricky part with Rmarkdown, is that it may behave different in Rstudio than for Rscript (or for Microsoft R). To add more salt into the wound, R also suffers from package hell… just like for any other programming language R is not that different with its package dependencies.

The steps under the hood

All in all, what this examples does, are the following

  • From a static blog page, which actually is this page (uhuh!), link to a dynamic PHP page where the vistor enters a Yahoo finance ticker along with name and e-mail address.
    • The dynamic page controls if correct API secret is entered and the entry of legit e-mail address and legit alphanumeric name.
  • The user input, is then saved as a “server cookie” which is to be fetched within a timeframe of 10 minutes.
    • After this “server cookie” step, there might be bugs due to time outs of the Yahoo Finance page. A preferable fix, would be to instead of a server cookie use a message queue such as RabbitMQ, and then timeouts and other bugs and issues may vanish.
  • A service fetches the server cookie once a while to
    • fetch data for given ticker, and to
    • figure out corresponding currency for the ticker, and to
    • compile a Rmarkdown script into PDF.
  • E-mail the compiled PDF to the visitor.
  • Clear all data regardless of success of fail in the chain of processes.


At this moment your e-mail is not saved when using the API but that may change in the future to prevent abuse.

Hope this works and “May all the containers be with you”. - Mikael Helin