Doubts regarding /Documents/:record/file/:field POST endpoint

Can anyone please tell how to hit /Documents/:record/file/:field POST endpoint using Postman?

It uses following payload scheme:

{
   "format":"sugar-html-json",
   "delete_if_fails":true,
   "oauth_token":"43b6b327-cc70-c301-3299-512ffb99ad97",
   "<attachment field>":"@\/path\/to\/ExampleDocument.txt"
}

I am not able to resolve the <attachment field> in the above payload.

  • Hello Aman, 

    You'll need to replace the <attachment field> with the name of the field that receives the file. On Documents, it's called 'filename'.

    I managed to test this Endpoint in Postman with the following settings:

    Can you have a look and let me know if this works for you? 

  • Yes, Its working. Thanks a lot.

  • Hello Andre,

    I tried the way you suggested.

    It is working fine when I first give the json payload and then pass the file in the form data, but if I construct the request with firstly passing file in form data and then passing the json, I am getting attachment missing error.

    Also, Is this endpoint accepts two media types (application/json and form-data) simultaneously in one request?

    One more thing is that this request is working fine even if I just provide the file in form-data and no json payload. Any idea why so?

    Thanks

  • Hi Aman, 

    If you want to get details on this or any request the best is to have a look at the file that is being used. 

    On this endpoint you should have a look here: 

    Fullscreen
    1
    sugar/modules/Documents/clients/base/api/DocumentsFileApi.php
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    This should help you to understand what's happening when you call this endpoint.