bittorrent / sync_api_sample

11 stars 0 forks source link

Include synchronizer token and cookie into the examples #1

Open voz opened 8 years ago

voz commented 8 years ago

The examples seem not to work anymore since the token is required as discussed here: http://forum.bittorrent.com/topic/41600-couldnt-use-all-post-apis/

voz commented 8 years ago

Just for the record, here is an example of how to make it work:

Get the token and save the cookie:

$ curl -c cookie.txt http://my_login:my_pass@localhost:8888/api/v2/token

The response is:

{ "data": { "token": "DJ0UbLq2mWnZMrL-KBY9wuQvfS_ikBC9brHJPRnL2ff7CTUA6fiBRHmzf1YAAAAA" }, "method": "GET", "path": "/api/v2/token", "status": 0 }

Use the token and the cookie when sending requests:

curl -b cookie.txt -u my_login:my_pass -X POST -H 'Content-Type: application/json' -d '{"timelimit": "60", "askapproval": 0, "permissions": 2}' http://localhost:8888/api/v2/folders/8615409530567225028/link?token=DJ0UbLq2mWnZMrL-KBY9wuQvfS_ikBC9brHJPRnL2ff7CTUA6fiBRHmzf1YAAAAA

The response is:

{ "data": { "link": "https://link.getsync.com/#f=BTSYNC%20TEST&sz=0&t=1&s=THUXWXBKRHBROECHIPDMDACAV7I767HFR7UYOSEA3BOG6HWWU46Q&i=CJ5SCO7FZDJA4DM5N73N6Q2EBBUHQG4WP&e=1451209760&v=2.2" }, "method": "POST", "path": "/api/v2/folders/8615409530567225028/link", "status": 0 }