Skip to content

Commit 8b2cd49

Browse files
committed
Fix curl example
Update docs for readability
1 parent 3d4d7e8 commit 8b2cd49

File tree

5 files changed

+130
-60
lines changed

5 files changed

+130
-60
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1+
# The WeTransfer Public API documentation
2+
13
<p align="center">
24
<!-- <img src="assets/artwork.jpg" alt="WeTransfer API Docs" width="100%" /> -->
35
<br>
46
<img src="https://img.shields.io/badge/License-MIT-yellow.svg?style=flat" />
57
</p>
68

7-
Getting Started
8-
---------------
9+
## Getting Started
910

1011
### Prerequisites
1112

1213
You're going to need:
1314

14-
- **Linux or OS X** Windows may work, but is unsupported.
15-
- **Ruby, version 2.3.1 or newer**
16-
- **Bundler** If Ruby is already installed, but the `bundle` command doesn't work, just run `gem install bundler` in a terminal.
15+
- **Linux or OS X** - Windows may work, but is unsupported.
16+
- **Ruby** - version 2.3.1 or newer
17+
- **Bundler** - If Ruby is already installed, but the `bundle` command doesn't work, just run `gem install bundler` in a terminal.
1718

18-
### Getting Set Up
19+
## Getting Set Up
1920

2021
Initialize and start the docs:
2122

@@ -26,10 +27,12 @@ bundle exec middleman server
2627

2728
You can now see the docs at http://localhost:4567. Whoa! That was fast!
2829

29-
### Building static files
30+
## Building static files
3031

3132
To create an exportable set of files, run the following command:
3233

33-
`bundle exec middleman build --no-clean`
34+
```shell
35+
bundle exec middleman build --no-clean
36+
```
3437

3538
This will output the static files in the `/docs` folder.

source/includes/_board-api.md

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const board = await wtClient.board.create({
2929

3030
client = WeTransfer::Client.new(api_key: 'YOUR PRIVATE API KEY GOES HERE')
3131

32-
board = client.create_board_and_upload_items(name: 'Kittens') do |builder|
32+
board = client.create_board_and_upload_items(name: 'Little kittens') do |builder|
3333
builder.add_file(
3434
name: 'bobis.jpg',
3535
io: File.open('/path/to/kitty.jpg', 'rb')
@@ -75,11 +75,15 @@ puts "The board can be viewed on #{board.url}"
7575
}
7676
```
7777

78-
<aside class="warning"><strong>Note:</strong> The <code>url</code> in the response is the URL you will use to access the board you create! It is not returned at the end of the upload flow, rather right now when you create the empty board.</aside>
78+
<aside class="warning">**Note**: The `url` in the response is the URL you will use to access the board you created. It is not returned at the end of the upload flow, rather only right now when you create the (empty) board.</aside>
79+
80+
Later you'll want to interact with your board. Add files and links to it. In order to do that, make sure to note the value of the `id` property.
7981

8082
## Add links to a board
8183

82-
Once a board has been created you can add links like so:
84+
A board can hold files *and* URLs. Lets have a look at how you can add URLs to your board. For that you need the `id` of the board you created earlier, unless your SDK will handle that for you.
85+
86+
Once a board has been created you can add links like below:
8387

8488
```shell
8589
curl -i -X POST "https://dev.wetransfer.com/v2/boards/{board_id}/links" \
@@ -194,7 +198,7 @@ const fileItems = await apiClient.board.addFiles(board, [{
194198
"name": "big-bobis.jpg",
195199
"size": 195906,
196200
"multipart": {
197-
"id": "some.random-id--",
201+
"id": "some random id",
198202
"part_numbers": 1,
199203
"chunk_size": 195906
200204
},
@@ -203,17 +207,23 @@ const fileItems = await apiClient.board.addFiles(board, [{
203207
]
204208
```
205209

206-
The endpoint will return an object for each file you want to add to the board. Each file must be split into chunks, and uploaded to a pre-signed S3 URL, provided by the following endpoint.
210+
The endpoint will return an object for each file you want to add to the board. The data returned is helpful in the next step when we want to request a place where we can upload our file.
211+
212+
The important parts in the response are the `id` of the file, the `id` of the multipart object, together with its `part_numbers`.
207213

208214
**Important**
209215

210-
Board chunks _must_ be 6 megabytes in size, except for the very last chunk, which can be smaller. Sending too much or too little data will result in a 400 Bad Request error when you finalise the file.
216+
Board chunks _must_ be 6 megabytes (or more precisely 6291456 bytes) in size, except for the very last chunk, which can be smaller. Sending too much or too little data will result in a `400 Bad Request` error when you finalize the file. As with transfers: Do not let us down.
211217

212218
<h2 id="board-request-upload-url">Request upload URL</h2>
213219

220+
Now that you've informed us about the file(s) you want to upload, it is time to request upload URLs. Each chunk of the file has its own upload url.
221+
214222
<h3 class="call"><span>GET</span> /boards/{board_id}/files/{file_id}/upload-url/{part_number}/{multipart_upload_id}</h3>
215223

216-
To be able to upload a file, it must be split into chunks, and uploaded to different presigned URLs. This route can be used to fetch presigned upload URLS for each of a file's parts. These upload URLs are essentially limited access to a storage bucket hosted with Amazon. They are valid for an hour and must be re-requested if they expire.
224+
To be able to upload a file, it must be split into chunks, and uploaded to different pre-signed URLs. This endpoint can be used to get pre-signed upload URLs for each of a file's parts. These upload URLs are essentially limited access to a storage bucket hosted with Amazon. They are valid for an hour and must be re-requested if they expire.
225+
226+
Use the fields from the previous response; now you need the `id` of the file, the `id` of the multipart, and you must request a upload-url for all of your `part_numbers`.
217227

218228
```shell
219229
curl -i -X GET "https://dev.wetransfer.com/v2/boards/{board_id}/files/{file_id}/upload-url/{part_number}/{multipart_upload_id}" \
@@ -269,15 +279,15 @@ for (
269279

270280
```json
271281
{
272-
"url": "https://presigned-s3-put-url"
282+
"url": "https://a-very-long-pre-signed-s3-put-url"
273283
}
274284
```
275285

276-
The Response Body contains the presigned S3 upload `url`.
286+
The response body contains the pre-signed S3 upload `url`. You will use that in the next step, when you upload the contents.
277287

278288
##### 401 (Unauthorized)
279289

280-
If the requester tries to request an upload URL for a file that is not in one of the requester's boards, we will respond with 401 UNAUTHORIZED.
290+
If you try to request an upload URL for a file that is not in one of your boards, the response will have a status code of 401 UNAUTHORIZED.
281291

282292
##### 400 (Bad request)
283293

@@ -287,7 +297,7 @@ If a request is made for a part, but no `multipart_upload_id` is provided; we wi
287297

288298
<h3 id="board-upload-part" class="call"><span>PUT</span> {signed_url}</h3>
289299

290-
Please note: errors returned from S3 will be sent as XML, not JSON. If your response parser is expecting a JSON response it may throw an error here. Please see AWS' <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html" target="_blank">S3 documentation</a> for more details about specific responses.
300+
You're communicating directly with Amazons' S3, not with our API. Please note: errors returned from S3 will be sent as XML, not JSON. If your response parser is expecting a JSON response it may throw an error here. Please see AWS' <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html" target="_blank">S3 documentation</a> for more details about specific responses.
291301

292302
```shell
293303
curl -i -T "./path/to/big-bobis.jpg" "https://signed-s3-upload-url"
@@ -404,10 +414,10 @@ curl -i -X GET "https://dev.wetransfer.com/v2/boards/{board_id}" \
404414
{
405415
"id": "random-hash",
406416
"name": "kittie.gif",
407-
"size": 1024,
417+
"size": 195906,
408418
"multipart": {
409419
"part_numbers": 1,
410-
"chunk_size": 1024
420+
"chunk_size": 195906
411421
},
412422
"type": "file"
413423
},
@@ -425,8 +435,11 @@ curl -i -X GET "https://dev.wetransfer.com/v2/boards/{board_id}" \
425435

426436
##### 403 (Forbidden)
427437

428-
If the requester tries to request a board that is not in one of the requester's boards, we will respond with 403 FORBIDDEN.
438+
If you try to request a board that is not yours, we will respond with 403 FORBIDDEN.
429439

430440
```json
431-
{"success":false, "message":"This board does not belong to you"}
441+
{
442+
"success":false,
443+
"message":"This board does not belong to you"
444+
}
432445
```

source/includes/_sdks.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
## V2 and V1 Compatible SDKs
44

5-
These SDKs are or soon will be compatible with V1 and V2 of the WeTransfer API. Feel free to file
6-
issues or PRs to help them along! :)
5+
These SDKs are or soon will be compatible with V1 and V2 of the WeTransfer API. Feel free to file issues or PRs to help them along! :)
76

87
<section class="sdks">
98
<article class="sdk sdk-node">

source/includes/_transfer-api.md

Lines changed: 89 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,22 @@ Transfers must be created with files. Once the transfer has been created and fin
1212

1313
When you create a transfer, you must include at least one file in the transfer create request.
1414

15+
Creating a transfer is to inform the API that you want to create a transfer (with at least one file), but you aren't sending the files already.
16+
17+
What you are sending is the `message`, a property that describes what this transfer is about, and a collection of file `name`s and their `size`. This allows the API to set up a place where your files can be uploaded to in a later state. Make sure the size of the file is accurate. Please don't lie to us; we will not be able to handle your files in a later stage...
18+
1519
```shell
1620
curl -i -X POST "https://dev.wetransfer.com/v2/transfers" \
1721
-H "Content-Type: application/json" \
18-
-H "x-api-key: your_api_key" \
19-
-H "Authorization: Bearer jwt_token" \
20-
-d '{"message":"My very first transfer!","files":[
21-
{"name":"big-bobis.jpg", "size":195906}, "name":"kitty.jpg", "size":369785]}'
22+
-H "x-api-key: REPLACE_WITH_YOUR_API_KEY" \
23+
-H "Authorization: Bearer REPLACE_WITH_YOUR_TOKEN" \
24+
-d '
25+
{
26+
"message":"My very first transfer!","files":[
27+
{"name":"big-bobis.jpg", "size":195906},
28+
{"name":"kitty.jpg", "size":369785}
29+
]
30+
}'
2231
```
2332

2433
```javascript
@@ -82,37 +91,44 @@ puts "The transfer can be viewed on #{transfer.url}"
8291

8392
```json
8493
{
85-
"id": "random-hash",
86-
"message": "My very first transfer!",
87-
"state": "uploading",
88-
"files": [
94+
"message" : "My very first transfer!",
95+
"files" : [
8996
{
90-
"id": "random-hash",
91-
"name": "big-bobis.jpg",
92-
"size": 195906,
93-
"multipart": {
94-
"part_numbers": 1,
95-
"chunk_size": 5242880
96-
}
97+
"multipart" : {
98+
"part_numbers" : 1,
99+
"chunk_size" : 195906
100+
},
101+
"size" : 195906,
102+
"type" : "file",
103+
"name" : "big-bobis.jpg",
104+
"id" : "c964caf6c54343f3b6e9610cb4ac5ea220181019143517"
97105
},
98106
{
99-
"id": "random-hash",
100-
"name": "kitty.jpg",
101-
"size": 369785,
102-
"multipart": {
103-
"part_numbers": 1,
104-
"chunk_size": 5242880
105-
}
107+
"multipart" : {
108+
"part_numbers" : 1,
109+
"chunk_size" : 369785
110+
},
111+
"size" : 369785,
112+
"type" : "file",
113+
"id" : "e7f74773661f2be2bec90e6322864abd20181019143517",
114+
"name" : "kitty.jpg"
106115
}
107-
]
116+
],
117+
"url" : null,
118+
"id" : "32a6ef6003f1429be0cf1674dd8fbdef20181019143517",
119+
"state" : "uploading"
108120
}
109121
```
110122

111123
Creates a new transfer with specified files.
112124

113-
## Request upload URL
125+
## Request upload URLs
126+
127+
If you look at that response above, you see some pointers that are needed now. All files should be uploaded to a specific place. You just have to get the place from our API. To do that, you ask the API based on the `transfer.id`, each and every `file.id`, and for each part (based on the `file.multipart.part_numbers` property).
128+
129+
To be able to upload a file, it must be split into parts and then each part will be uploaded to pre-signed AWS S3 URLs.
114130

115-
To be able to upload a file, it must be split into parts and then each part will be uploaded to presigned AWS S3 URLs. This route can be used to fetch presigned upload URLS for each of a file's parts. These upload URLs are essentially limited access to a storage bucket hosted with Amazon. NB: They are valid for an <em>hour</em> and must be re-requested if they expire.
131+
This endpoint can be used to get pre-signed upload URLS for each of a file's parts. These upload URLs are essentially limited access to a storage bucket hosted with Amazon. NOTE: They are valid for an **hour** and must be re-requested if they expire.
116132

117133
```shell
118134
curl -i -X GET "https://dev.wetransfer.com/v2/transfers/{transfer_id}/files/{file_id}/upload-url/{part_number}" \
@@ -176,24 +192,46 @@ Transfer chunks must be 5 megabytes in size, except for the very last chunk, whi
176192
}
177193
```
178194

179-
The Response Body contains the presigned S3 upload `url`.
195+
The Response Body contains the pre-signed S3 upload `url`.
180196

181197
##### 404 (Not found)
182198

183-
If the requester tries to request an upload URL for a file that is not in one of the requester's transfers, we will respond with 404 Not found.
199+
If you try to request an upload URL for a file that is not in the transfers, the API will respond with 404 Not found.
200+
201+
```json
202+
{
203+
"success" : false,
204+
"message" : "Couldn't find FileObject"
205+
}
206+
```
207+
208+
##### 417 (Expectation Failed)
209+
210+
If you request to upload part `0`, our API will tell you that our parts are numbered for humans; we start counting at part 1:
211+
212+
```json
213+
{
214+
"success" : false,
215+
"message" : "Chunk numbers are 1-based"
216+
}
217+
```
184218

185219
<h2 id="transfer-file-upload">File Upload</h2>
186220

187221
<h3 id="transfer-upload-part" class="call"><span>PUT</span> {signed_url}</h3>
188222

223+
Time to actually upload (chunks of) your file. With the pre-signed-upload-url you retrieved in the previous step, you can start uploading!
224+
225+
You will interact directly with Amazon S3. As such, we have no control over the messages sent by S3.
226+
189227
Important: errors returned from S3 will be sent as XML, not JSON. If your response parser is expecting a JSON response it may throw an error here. Please see AWS' <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html" target="_blank">S3 documentation</a> for more details about specific responses.
190228

191229
```shell
192230
curl -i -T "./path/to/big-bobis.jpg" "https://signed-s3-upload-url"
193231
```
194232

195233
```javascript
196-
// Use your favourite JS
234+
// Use your favorite JS
197235
const fs = require('fs');
198236

199237
const file = transfer.files[0];
@@ -230,7 +268,9 @@ for (
230268

231269
<h2 id="transfer-complete-file-upload">Complete a file upload</h2>
232270

233-
Finalize a file. Once all the parts have been uploaded succesfully, you use this endpoint to tell the system that it can start splicing the parts together to form one whole file.
271+
In the previous step, you've uploaded your file (potentially in parts) directly to S3. The WeTransfer API has no idea when that is complete. This call informs your transfer object that all the uploading for your file is done.
272+
273+
Again, to inform the API about this event, you need both the transfer id and the file id. Not only that, you currently also have to inform this endpoint on the amount of part numbers.
234274

235275
```shell
236276
curl -i -X PUT "https://dev.wetransfer.com/v2/transfers/{transfer_id}/files/{file_id}/upload-complete" \
@@ -280,9 +320,22 @@ await wtClient.transfer.completeFileUpload(transfer, file);
280320
}
281321
```
282322

323+
##### 417
324+
325+
If you try to finalise a file, but didn't actually upload all chunks it will respond with something like this:
326+
327+
```json
328+
{
329+
"success": false,
330+
"message": "Chunks 1 are still missing"
331+
}
332+
```
333+
283334
<h2 id="finalize-a-transfer">Finalize a transfer</h2>
284335

285-
Finalize the whole transfer. Once all the parts have been uploaded and finalized, you use this endpoint to tell the system that everything has been completely uploaded.
336+
After all files are uploaded and finalized, you can close the transfer for modification, and make it available for download.
337+
338+
You do that by calling this endpoint. It informs the API that everything has been completely uploaded.
286339

287340
```shell
288341
curl -i -X PUT "https://dev.wetransfer.com/v2/transfers/{transfer_id}/finalize" \
@@ -322,12 +375,14 @@ console.log(finalTransfer.url);
322375

323376
##### 200 (OK)
324377

378+
If all went well, the API sends you a lot of data. One of them being the `url`. That is the thing you will use to access the files in a browser.
379+
325380
```json
326381
{
327382
"id": "random-hash",
328383
"state": "processing",
329-
"message": "Little kittens",
330-
"url": "https://we.tl/t-smaller-random-hash",
384+
"message": "My first transfer!",
385+
"url": "https://we.tl/t-12344657",
331386
"files": [
332387
{
333388
"id": "random-hash",
@@ -343,7 +398,7 @@ console.log(finalTransfer.url);
343398
```
344399

345400
<aside class="notice">
346-
The <code>url</code> field is where you get the link you will need to access the transfer!
401+
The `url` field is where you get the link you will need to access the transfer!
347402
</aside>
348403

349404
##### 400 (Bad Request)
@@ -352,4 +407,4 @@ This is returned if the transfer can no longer be written to, or is it ready to
352407

353408
##### 403 (Unauthorized)
354409

355-
When you try to access something you don't have access to.
410+
When you try to finalize a transfer you don't have access to.

source/index.html.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ You can use our API to share files, links and love all over the world.
2323

2424
## Our APIs
2525

26-
Depending on what you want to make we have two different APIs: transfers and boards.
26+
Depending on what you want to make we have two main tastes: **transfers** and **boards**.
2727

2828
<div class="two-col">
2929
<div class="col">

0 commit comments

Comments
 (0)