Forum Discussion

PerBonomi's avatar
11 years ago

REST API. Getting error posting new message

Hi folks. I'm using the API to post a new message, following instructions here:

 

http://community.lithium.com/t5/Community-API/bd-p/developers-rest-api?leaf-id=Board.messages.post#Board.messages.post

 

The string I submit should be able to have a limit of 1,000,000 characters, but I get an error around the 7,000 mark.

 

Using this code works fine if the body string I pass is below 7,000 or 8,000 characters:

vBody = <string of about 8,000 chars>;

$.post("/restapi/vc/boards/id/genericboard/messages/post?message.subject=subject&message.author=/users/login/Per&message.body=" + vBody );

When that string goes over 7/8k I get this error:

 

HTTP/1.1 413 Request Entity Too Large

 

Any advice? Is the API documentation wrong about the 1MM limit or am I using it wrong?

4 Replies

  • HaidongG's avatar
    HaidongG
    Lithium Alumni (Retired)
    11 years ago

    Hi PerBonomi 

     

    Maybe you should not put the message body as part of the URL, but as part of HTTP POST? just like format submission.

     

     

     

     

  • You're probably hitting a limit on the URL parameter length.

     

    Try adding the message body as data to the post request, like this:

    $.post(
       "/restapi/vc/boards/id/genericboard/messages/post",
       {
    "message.body": vBody,
    "message.subject": subject,
    "message.author": "/users/login/Per"
    } );

     

  • NoamanA's avatar
    NoamanA
    Lithium Alumni (Retired)
    11 years ago

    Hey Per

     

    I'm afraid that in this case our documentation is incorrect.

     

    Unfortunately, the API isn't designed to carry that much content over the URL.  According to best practices, POST parameters ought to be passed via the HTTP POST body using using 'application/x-www-form-urlencoded' or 'multipart/form-data' encoding, which would require extra work on your part.

     

    As it stands there's no way for us to increase the limit.  Apologies for being misled on this.  I'll make a request for our docs to be updated.

     

    Regards

    Noaman

  • PerBonomi's avatar
    PerBonomi
    Boss
    11 years ago

    Thanks for all your responses, it works brilliantly with http post :)