Skip to content

Commit a1ea7aa

Browse files
arnoFlemingbermannoah
authored andcommitted
Fix curl example (#80)
* Fix curl example Update docs for readability * Rebase master and rebuild * Readable JSON body
1 parent 3d4d7e8 commit a1ea7aa

28 files changed

+253
-115
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.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

docs/images/sdks/php-ab3973ac.svg.gz

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

docs/images/sdks/r-c8f72e0e.svg.gz

0 Bytes
Binary file not shown.

docs/images/sdks/ruby-88f255a7.svg.gz

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

docs/index.html

Lines changed: 116 additions & 55 deletions
Large diffs are not rendered by default.

docs/index.html.gz

1.59 KB
Binary file not shown.

docs/javascripts/all-2fffc1ac.js.gz

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

docs/v1/images/sdks/r-c8f72e0e.svg.gz

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

docs/v1/index.html.gz

0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

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: 96 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,29 @@ 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!",
27+
"files":[
28+
{
29+
"name":"big-bobis.jpg",
30+
"size":195906
31+
},
32+
{
33+
"name":"kitty.jpg",
34+
"size":369785
35+
}
36+
]
37+
}'
2238
```
2339

2440
```javascript
@@ -82,37 +98,44 @@ puts "The transfer can be viewed on #{transfer.url}"
8298

8399
```json
84100
{
85-
"id": "random-hash",
86-
"message": "My very first transfer!",
87-
"state": "uploading",
88-
"files": [
101+
"message" : "My very first transfer!",
102+
"files" : [
89103
{
90-
"id": "random-hash",
91-
"name": "big-bobis.jpg",
92-
"size": 195906,
93-
"multipart": {
94-
"part_numbers": 1,
95-
"chunk_size": 5242880
96-
}
104+
"multipart" : {
105+
"part_numbers" : 1,
106+
"chunk_size" : 195906
107+
},
108+
"size" : 195906,
109+
"type" : "file",
110+
"name" : "big-bobis.jpg",
111+
"id" : "c964caf6c54343f3b6e9610cb4ac5ea220181019143517"
97112
},
98113
{
99-
"id": "random-hash",
100-
"name": "kitty.jpg",
101-
"size": 369785,
102-
"multipart": {
103-
"part_numbers": 1,
104-
"chunk_size": 5242880
105-
}
114+
"multipart" : {
115+
"part_numbers" : 1,
116+
"chunk_size" : 369785
117+
},
118+
"size" : 369785,
119+
"type" : "file",
120+
"id" : "e7f74773661f2be2bec90e6322864abd20181019143517",
121+
"name" : "kitty.jpg"
106122
}
107-
]
123+
],
124+
"url" : null,
125+
"id" : "32a6ef6003f1429be0cf1674dd8fbdef20181019143517",
126+
"state" : "uploading"
108127
}
109128
```
110129

111130
Creates a new transfer with specified files.
112131

113-
## Request upload URL
132+
## Request upload URLs
133+
134+
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).
135+
136+
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.
114137

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.
138+
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.
116139

117140
```shell
118141
curl -i -X GET "https://dev.wetransfer.com/v2/transfers/{transfer_id}/files/{file_id}/upload-url/{part_number}" \
@@ -176,24 +199,46 @@ Transfer chunks must be 5 megabytes in size, except for the very last chunk, whi
176199
}
177200
```
178201

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

181204
##### 404 (Not found)
182205

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.
206+
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.
207+
208+
```json
209+
{
210+
"success" : false,
211+
"message" : "Couldn't find FileObject"
212+
}
213+
```
214+
215+
##### 417 (Expectation Failed)
216+
217+
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:
218+
219+
```json
220+
{
221+
"success" : false,
222+
"message" : "Chunk numbers are 1-based"
223+
}
224+
```
184225

185226
<h2 id="transfer-file-upload">File Upload</h2>
186227

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

230+
Time to actually upload (chunks of) your file. With the pre-signed-upload-url you retrieved in the previous step, you can start uploading!
231+
232+
You will interact directly with Amazon S3. As such, we have no control over the messages sent by S3.
233+
189234
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.
190235

191236
```shell
192237
curl -i -T "./path/to/big-bobis.jpg" "https://signed-s3-upload-url"
193238
```
194239

195240
```javascript
196-
// Use your favourite JS
241+
// Use your favorite JS
197242
const fs = require('fs');
198243

199244
const file = transfer.files[0];
@@ -230,7 +275,9 @@ for (
230275

231276
<h2 id="transfer-complete-file-upload">Complete a file upload</h2>
232277

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.
278+
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.
279+
280+
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.
234281

235282
```shell
236283
curl -i -X PUT "https://dev.wetransfer.com/v2/transfers/{transfer_id}/files/{file_id}/upload-complete" \
@@ -280,9 +327,22 @@ await wtClient.transfer.completeFileUpload(transfer, file);
280327
}
281328
```
282329

330+
##### 417
331+
332+
If you try to finalise a file, but didn't actually upload all chunks it will respond with something like this:
333+
334+
```json
335+
{
336+
"success": false,
337+
"message": "Chunks 1 are still missing"
338+
}
339+
```
340+
283341
<h2 id="finalize-a-transfer">Finalize a transfer</h2>
284342

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.
343+
After all files are uploaded and finalized, you can close the transfer for modification, and make it available for download.
344+
345+
You do that by calling this endpoint. It informs the API that everything has been completely uploaded.
286346

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

323383
##### 200 (OK)
324384

385+
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.
386+
325387
```json
326388
{
327389
"id": "random-hash",
328390
"state": "processing",
329-
"message": "Little kittens",
330-
"url": "https://we.tl/t-smaller-random-hash",
391+
"message": "My first transfer!",
392+
"url": "https://we.tl/t-12344657",
331393
"files": [
332394
{
333395
"id": "random-hash",
@@ -343,7 +405,7 @@ console.log(finalTransfer.url);
343405
```
344406

345407
<aside class="notice">
346-
The <code>url</code> field is where you get the link you will need to access the transfer!
408+
The `url` field is where you get the link you will need to access the transfer!
347409
</aside>
348410

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

353415
##### 403 (Unauthorized)
354416

355-
When you try to access something you don't have access to.
417+
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)