You need to sign in to do that
Don't have an account?
Elizabete Fonseca
[{"message":"The HTTP entity body is required, but this request has no entity body.","errorCode":"JSON_PARSER_ERROR"}]
Hi there!
I'm trying to test a apexrest api that I just built, but I can't seem to get past this error:
[{"message":"The HTTP entity body is required, but this request has no entity body.","errorCode":"JSON_PARSER_ERROR"}]
What exactly does this mean "The HTTP entity body is required, but this request has no entity body."? And how can I set the entity body in the request?
I've looked through almost all of the similar issues I found online and tried the solutions, but still nothing worked for me.
I'm using CURL to make this request:
And the apexrest code is:
Thanks in advance!
EF
I'm trying to test a apexrest api that I just built, but I can't seem to get past this error:
[{"message":"The HTTP entity body is required, but this request has no entity body.","errorCode":"JSON_PARSER_ERROR"}]
What exactly does this mean "The HTTP entity body is required, but this request has no entity body."? And how can I set the entity body in the request?
I've looked through almost all of the similar issues I found online and tried the solutions, but still nothing worked for me.
I'm using CURL to make this request:
curl -X POST 'https://myinstance.salesforce.com/services/apexrest/v1/MyRestApi?param1=value1&...' -H 'Content-Type: application/json' -H 'Content-Length: 0' -H 'Accept-type: application/json' -H 'Authorization:Bearer myaccesstoken'
And the apexrest code is:
@RestResource(urlMapping='/v1/MyRestApi/*') global class MyRestApi { @HttpPost global static void doPost(String param1, ...){ map<String, Object> JSONResponseMap = (...); JSON.serialize(JSONResponseMap); RestContext.response.responseBody = Blob.valueOf(JSON.serialize(JSONResponseMap)); } }If anyone has any idea of what's missing or what I am doing wrong, I would greatly appreciate some guidance!
Thanks in advance!
EF
- If you don't want to send data in request then use
- If you want to send data in the request then use below:-
Also, if you like to only change in your curl cmd only then try with some data :-
Hope this helps.
Hi Manish Bhati,
Thanks so much for responding!
I tried your suggestions all of your suggestions but I got errors in all of them:
1st - about the MISSING Content-Type and Length;
2nd - about the INVALID SESSION ID;
3rd - same error about the entitty body required.
Any other ideas why is this could be?
Thanks a million for your assistance!
Cheers,
EF
Then we can figure out the problem.
Also, let me know whether in method doPost you are creating request or not.
I tried as you suggested and I get this error:
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]
because there's no access_token.
I the doPost method I do not create the request, but rather the response... is that what you are asking?
Thanks for your assistance :)
Cheers,
EF
Try 1:- or if you could save json file in the folder where you are running this curl cmd from:-
- Save a file named newaccount.json
- with the below data
- run the below curl cmd from where the file newaccount.json reside, crosscheck the file is not newaccount.json.txt if you create from text doc.
I apologize for leaving you hanging yesterday... but some other stuff came up and I had to prioritize.
I tried the 2 ways you suggested and both worked!
I believe the reason why I was having problems was because of the " (double quotes) / ' (single quotes) situation, which can be tricky to figure out depending on the machine you are using.
I use Linux, so for anyone that might encounter this in the future, it seems that everything needs to be enclosed in single quotes: or
Once again, Manish, thank you so much for your assistance!
Best regards,
EF