1

I am trying to implement a webhook from a 3rd party application (Eventbrite) using a Custom REST API in Salesforce.The issue here is that 3rd party API uses "Accept: text/plain" parameter in their Request Header and because of that Apex REST API rejects all inbound api request with below error.

[{"errorCode":"NOT_ACCEPTABLE","message":"Accept header specified in HTTP request is not supported: text/plain"}]

I have checked in the 3rd party application (Eventbrite) docs and it seems like we cannot change the format of the request . As per Salesforce documentation, it only supports Support for JSON and XML as HTTP ACCEPT header.

I am just wondering , is there any way to support "text/plain " as Accept header ?

Request Header from Eventbrite Webhook

 Request Headers

X-Eventbrite-Event: test
Accept: text/plain
X-Eventbrite-Delivery: 1078584
User-Agent: Eventbrite Hookshot 91008c8
Content-type: application/json
User-ID-Sender: 106077679079

[EDIT] :Here is the code snippet I am using

 @HttpPost
    global static String createWebhookRequest()
    {


        RestRequest request = RestContext.request;
        Webhook__c hook= new Webhook__c(
        Message__c = request.requestBody.toString());
        insert hook;
        return String.valueOf(hook.id);

    }

Here is the documentation I am referring to . https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_rest_resources.htm

Is there a possible workaround to this issue?

4
  • Can you link the documentation which mentions Salesforce only accepts text/plain? I tried setting the header value Accept to text/plain and called a custom REST API, and it just works fine. How is your API written, do you have any condition to block such requests, providing such details will help here.
    – Jayant Das
    Commented Apr 10, 2019 at 14:09
  • @JayantDas No, I dont have any conditions to block such request types. Please see the code snippet below.
    – Arun
    Commented Apr 11, 2019 at 12:41
  • If you have any code snippet to provide, please edit your question and add necessary details.
    – Jayant Das
    Commented Apr 11, 2019 at 12:47
  • updated the question with more details. @JayantDas Is it possible to share your code which is working with Accept='text/plain'
    – Arun
    Commented Apr 11, 2019 at 13:00

1 Answer 1

1

As for your question:

Apex Rest API : Is it possible to support accept parameter with “plain/text”

Based on an example (details below), Yes.

The documentation that you have referenced mentions that there's a support for JSON/XML, but does not mention that no other Request Header Accept attribute can be accepted.

As an example, below is what I sent to a custom web service and it worked fine.

My Web Service

@HttpPost
global static void myRESTMethod() {
    RestRequest r = RestContext.request;
    System.debug('Request Headers:' + r.headers);
    ...
    RestResponse res = RestContext.response;
    res.responseBody = Blob.valueOf('OK');
    res.statusCode = 200;
}        

Client invoking the Web Service (POSTMAN/Workbench)

Content-Type:application/json
Accept:text/plain

Debug Logs

USER_DEBUG [10]|DEBUG|Request Headers:{Accept=text/plain, .....}

And the client receives a 200 response along with the value OK.

1
  • Thanks Jayant. I realized the issue was due to the return type I had and once I added a valid "200" status code with OK response, it is working fine.
    – Arun
    Commented Apr 12, 2019 at 2:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .