Search code examples
phpjavascriptoauthtrello

How to log in via OAuth so a cron job can run


Not 100% sure I worded the title correctly, but here is what I want to do.

I have written a small page that is mostly JS & a small PHP scraper. The script runs, connects to Trello, based on what it finds, it scrapes another site using the PHP scraper, and then updates some cards in Trello.

This is fine as a page I can load up in a browser, but I want to set it up as a page that runs as a cron job on our server. I don't know how to modify my script to automatically log into Trello. I know I could run it once, authorize for 30 days etc., but ideally I don't want to keep having to do that. I'm a little unfamiliar with this, so any reco's on how best to approach it are welcome.

**Moved from webapps


Solution

  • It's probably easiest to generate a non-expiring API token, instead of trying to simulate logging into Trello.

    First, generate an application key at

    https://trello.com/1/appKey/generate

    Then, generate a non-expiring read/write token at

    https://trello.com/1/authorize?key=substitutewithyourapplicationkey&name=My+Application&expiration=never&response_type=token&scope=read,write

    That should be enough to do board and card GETs and PUTs, and you don't have to worry about getting a new token, because it won't ever expire.

    For example, you could read a board:

    GET https://api.trello.com/1/boards/id_of_board?key=substitutewithyourapplicationkey&token=substitutewithyournonexpiringtoken

    or modify a card

    PUT https://api.trello.com/1/cards/id_of_card?desc=New%20Description&key=substitutewithyourapplicationkey&token=substitutewithyournonexpiringtoken

    For more details, see https://trello.com/docs and https://trello.com/api