How do I resolve Error 8727 in REST API to upload PDF file?
I want to develop a REST API for uploading PDF files. I started with OPENAPI spec file. When I test, I get error 8727 referencing missing required parameter file.
"{"$c(13,10,9)"""errors"":[ {"$c(13,10,9,9,9)"""code"":8727,"$c(13,10,9,9,9)"""domain"":""%ObjectErrors"","$c(13,10,9,9,9)"""error"":""ERROR #8727: Parameter required: file."","$c(13,10,9,9,9)"""id"":""RESTRequired"","$c(13,10,9,9,9)"""params"":[""file"""$c(13,10,9,9,9)"]"$c(13,10,9,9)"}"$c(13,10,9)"],"$c(13,10,9)"""summary"":""ERROR #8727: Parameter required: file."""$c(13,10)"}"
OpenAPI spec (openapi folder), generated code (pdf folder), test method (test folder) and error message (README) are all captured in this GitHub repo:
I sent the test request to an Interoperability production to review the request. I copied and pasted beginning and end into the ReadMe file.
I cannot identify what is wrong with my request. How do I generate a valid request? Or how should I update the OpenAPI spec to get it to work?
Comments
I think the Content-Type header in the request is missing the boundary parameter, leading to the .disp method not seeing the « file » part
Here is an example :
POST /upload HTTP/1.1
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="username"
john_doe
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="profile_picture"; filename="profile.jpg"
Content-Type: image/jpeg
[Binary data of the JPEG file]
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="metadata"
Content-Type: application/json
{"age": 30, "location": "New York"}
------WebKitFormBoundary7MA4YWxkTrZu0gW--j