Short link creation and management


Go to CloudFormation service in your AWS Console.


Choose the stack you created for the Telegram bot (Bot and API Setup section in Setup instructions).


To work with the API, use the HttpApiUrl from the Outputs tab. For example,  https://xxx.execute-api.us-east-1.amazonaws.com/ 



Authorization


All commands must contain an authorization token in the header. To get it, you need to make a POST request /login

Username and password were defined when the bot stack was used. 

curl -d '{"username":"admin@gmail.com","password":"pass"}' -H "Content-Type: application/json" -X POST https://xxx.execute-api.us-east-1.amazonaws.com/login

If successful, the responce will contain the 'AccessToken' field

{"success": true, "message": "Auth ok", "items": [], "auth": {"AccessToken": "eyJraWQ...5EuFopT80A", "ExpiresIn": 3600, "TokenType": "Bearer"}}

 

 Methods


All other queries have to go to the endpoint '/colinks' 


GET allows you to get the current list of the short links.

curl https://xxx.execute-api.us-east-1.amazonaws.com/colinks -H "Authorization: Bearer eyJraWQ...80A"


sample response: 

{"lastKey": 0, "items": [{"short": "test", "full": "https://duckduckgo.com/"}, {"short": "3edb46bc", "full": "https://www.google.com"}]}

POST allows you to create new short links. Specify a relative URL as "short" parameter, and target address as "full".

curl -d '{"short":"test", "full":"https://duckduckgo.com/"}' -H "Content-Type: application/json" -H "Authorization: Bearer AAAA...AAAA" -X POST https://xxx.execute-api.us-east-1.amazonaws.com/colinks


PUT /{id} query allows you to edit existing short links. Specify an existing short link instead of {id}, and a new target address as full.

curl -d '{"full":"https://www.google.com"}' -H "Content-Type: application/json" -H "Authorization: Bearer AAAA...AAAA" -X PUT https://xxx.execute-api.us-east-1.amazonaws.com/colinks/test


The delete /{id} query allows you to delete an existing short link.

curl -H "Content-Type: application/json" -H "Authorization: Bearer AAAA...AAAA" -X DELETE https://xxx.execute-api.us-east-1.amazonaws.com/colinks/test