You need to sign in to do that
Don't have an account?
Hithesh Saicharan
Simple Rest service always giving Bad Message 400
I am planning to implement connected API for my application. So as a start I just wrote simple httpPost method and checked whether I can able to hit through post man.
and here is my simple code
Inorder to hit this method I created connected app and after giving client id, client secret, user name , password i got access_token as below
and here is my instance URL
and even I tried with
but I am always getting
For Headers I tried with Authorization = Bearer <access_token> or Authorization = OAuth <access_token>
and noting is working. I am not doing any fancy coding here. Not sure why its not working.
PS: Since this is my dev org I am sharing my access token. Later I will change the token once it got worked.
and here is my simple code
@RestResource(urlMapping='/PostToChatter') global class GetChatter{ @HTTPPost global static void createChatterRecords(){ System.debug('Success >>>'); RestResponse response = RestContext.response; response.addHeader('Content-Type', 'application/json'); response.responseBody = Blob.valueOf('{ "Excuted succesfully" : "EXECUTED" }'); response.statusCode = 201; } }
Inorder to hit this method I created connected app and after giving client id, client secret, user name , password i got access_token as below
00D2v000001e2OE!ARsAQHzfP_5D0wui2bSyRFg_M8slkwU3pK2t7cB99lqrMNDB8es1aDluf46dL.RpLKQQxPJrM1fwQyyfhG0NmfEeegB4h.b2
and here is my instance URL
https://hitheshm-dev-ed.lightning.force.com/services/apexrest/PostToChatter
and even I tried with
https://hitheshm-dev-ed.my.salesforce.com/services/apexrest/PostToChatter
but I am always getting
<h1>Bad Message 400</h1> <pre>reason: No Host</pre>
For Headers I tried with Authorization = Bearer <access_token> or Authorization = OAuth <access_token>
and noting is working. I am not doing any fancy coding here. Not sure why its not working.
PS: Since this is my dev org I am sharing my access token. Later I will change the token once it got worked.
All Answers
See example here
Let me know if it helps
I tried this at my end and could successfully get an expected response
In case you are using an older version of the postman, it does not permit/fetch to use the access token in your post-call.
Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you