Search code examples
salesforcewebhooksapexzendesk

Sending Zendesk ticket to salesforce


I want to send Zendesk ticket to Salesforce. I have used http target option in extension in zendesk and set the url of my visualforce page (Url: https://c.ap4.visual.force.com/apex/restOutput) and also enabled the Basic Authentication. When i send the test data from zendesk no logs are generated in salesforce developer console. The response sent by zendesk after sending the test data.

`

HTTP/1.1 200 OK
Date: Tue, 31 Jul 2018 04:53:09 GMT
Public-Key-Pins-Report-Only: pin-sha256="9n0izTnSRF+W4W4JTq51avSXkWhQB8duS2bxVLfzXsY="; pin-sha256="5kJvNEMw0KjrCAu7eXY5HZdvyCS13BbA0VJG1RSP91w="; pin-sha256="njN4rRG+22dNXAi+yb8e3UMypgzPUPHlv4+foULwl1g="; max-age=86400; includeSubDomains; report-uri="https://calm-dawn-26291.herokuapp.com/hpkp-report/nullm";
Expect-CT: max-age=0; report-uri="https://calm-dawn-26291.herokuapp.com/Expect-CT-report/nullm";
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Content-Security-Policy: upgrade-insecure-requests 
X-Robots-Tag: none
Cache-Control: no-cache,must-revalidate,max-age=0,no-store,private
Set-Cookie: BrowserId=EKk-yAZfRfOSD0AHf2etLA;Path=/;Domain=.force.com;Expires=Sat, 29-Sep-2018 04:53:09 GMT;Max-Age=5184000
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
Content-Encoding: gzip
Transfer-Encoding: chunked
Connection: close
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head></head><body onload="document.forms['workerForm'].submit()">
<form  accept-charset="UTF-8" action="https://ap4.salesforce.com/visualforce/session" enctype="application/x-www-form-urlencoded" id="workerForm" method="post" name="workerForm" ><input type="hidden" name="url" id="url" value="https://c.ap4.visual.force.com/apex/restOutput" />
</form>
</body>
</html>

`

My visual page code is as follows: `

<apex:page controller="myController">
</apex:page>

`

My controller is defined as

`

@RestResource(urlMapping='/restOutput')
global class myController {
    public myController(){
        System.debug('constructor');
       callBack();
    }
    @HttpPost
    global static void callBack()
    {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        System.debug(req.requestBody);
        //System.debug(ApexPages.currentPage().getParameters());
    }
}

`


Solution

  • Finally i got the solution, I was making mistake in consuming the api. To consume the salesforce api, send a post request with authorization header(containing access token),post data. The Request seems similar to.

      curl --request POST \
      --url https://ap4.lightning.force.com/services/apexrest/restOutput \
      --header '<access_token or sessionID' \
      --data '{\n"ticket_title":"Workbench Api Request Test",\n"ticket_description":"This is just a test Description",\n"ticket_status":"New",\n"requester_firstname":"Ebizon",\n"requester_lastname":"NetInfo",\n"requester_email":"[email protected]"\n}\n'