I am working on a Spring Jersey application where I need to import a document into Outline using their API. However, when I send the POST request to /documents.import, I receive a 400 Bad Request error, even though I am sending all the required parameters in the correct format.
What I am trying to do:
Download pages from a Coda document and convert them to Markdown.
Upload the Markdown file to Outline by making a multipart/form-data request.
Code I am using to send the request:
Client client = ClientBuilder.newBuilder().register(MultiPartFeature.class).build();
WebTarget outlineUploadTarget = client.target(OUTLINE_API_BASE_URL + "/documents.import");
File fileToUpload = filePath.toFile();
MultiPart multiPart = new FormDataMultiPart()
.field("collectionId", collectionId, MediaType.TEXT_PLAIN_TYPE)
.field("publish", "true", MediaType.TEXT_PLAIN_TYPE)
.field("template", "true", MediaType.TEXT_PLAIN_TYPE)
.bodyPart(new FileDataBodyPart("file", fileToUpload, MediaType.APPLICATION_OCTET_STREAM_TYPE));
try (Response response = outlineUploadTarget.request(MediaType.APPLICATION_JSON)
.header("Authorization", "Bearer " + OUTLINE_API_KEY)
.post(Entity.entity(multiPart, multiPart.getMediaType()))) {
System.out.println("UPLOAD RESPONSE: " + response.getStatus() + " " + response.readEntity(String.class));
}
// Cleanup multipart object
multiPart.close();
Request Parameters (as per API docs):
file (Markdown file)
collectionId (UUID of the collection)
publish (Boolean)
template (Boolean)
Issue:
Despite sending all the parameters correctly, I always receive 400 Bad Request. The Outline API documentation (linked below) does not specify additional requirements that I might be missing.
What I have tried:
Verified that collectionId is a valid UUID.
Ensured that the file exists and is correctly read before being uploaded.
Tried using different content types (MediaType.MULTIPART_FORM_DATA_TYPE, MediaType.APPLICATION_OCTET_STREAM_TYPE).
Checked for any missing authentication headers.
Outline's API Documentation: .import
PLEASE HELP ME AS TO WHAT SHOULD I DO
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743754243a4501462.html
评论列表(0条)