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());
}
}
`
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":"contact#ebizontek.com"\n}\n'
Related
I have a question, I do not understand why the cookie is not added. I have a frontend and backend on separate servers and at various ports, I hit the backend for a token. In response, he gets it, however, it is not set. Could someone look? Secure and httpOnly is deactivated. On the frontend side I have set withCredentials: true.
On the frontend side:
axios.defaults.withCredentials = true;
axios.post('http://backendhost:8584/login', user).then(response => {
if(response){
this.props.history.push('/home');
}
});
Cors On the api side:
#Bean
CorsConfigurationSource corsConfiguration() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.setAllowedOrigins(Collections.singletonList("*"));
config.setAllowedMethods(Collections.singletonList("*"));
config.setAllowedHeaders(Collections.singletonList("*"));
UrlBasedCorsConfigurationSource source =
new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
return source;
}
Set cookie on the auth server side:
response.addCookie(generateCookie("session-token", customer.getToken()));
public Cookie generateCookie(String key, String value) {
Cookie cookie = new Cookie(key,value);
cookie.setMaxAge(60 * 60 * 24 * 365);
cookie.setSecure(false);
cookie.setHttpOnly(false);
cookie.setPath("/");
return cookie;
}
And I get it in chrome:
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: http://frontendhost:8080
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Type: application/json
Date: Tue, 16 Jun 2020 16:30:11 GMT
Expires: 0
Pragma: no-cache
Referrer-Policy: no-referrer
Set-Cookie: session-token=eyJhbGciOiJSUz; Max-Age=31536000; Expires=Wed, 16-Jun-2021 16:30:11 GMT; Path=/
transfer-encoding: chunked
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
I have been trying to use React to make API calls, I am able to successfully run GET and POST requests but when i ran PATCH, it return 400 error which is bad request. But i am able to run the same request successfully on Postman.
I have a feeling I am not passing the data in the right format, but the body and the headers are being passed in the same form as in the POST method which is working fine.
Also, the preflight request is being passed as OK (200) but the connection closes at PATCH request
This is my request, where the Id is being received from another component which is then passed to the API.
class AddPatients extends React.Component {
constructor(props)
{
super(props);
this.state = {message :''};
console.log(this.props.list_id);
}
addPatients(url)
{
let xhr = new XMLHttpRequest();
xhr.open('PATCH',url, true);
xhr.setRequestHeader("Authorization", "Auth_key");
xhr.setRequestHeader("X-OHP-Developer-API-Key", "API_Key ");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Accept", "application/json");
let body = {
data:
[
{
//record 1
},
{
//record 2
}
]
}
const res = xhr.send(JSON.stringify(body));
console.log('the response is', res);
}
onButtonClick()
{
var url = 'the url link/' + this.props.list_id;
this.addPatients(url);
}
render() {
return(
<div>
<button onClick={this.onButtonClick.bind(this)}> Add patients to the list </button>
{this.props.list_id}
</div>
);
}
}
export default AddPatients;
It has nothing to do with the OPTIONS request i think because it returns OPTIONS IN Allow-Methods options like:
Request Method: OPTIONS
Status Code: 200 OK
Remote Address: 18.236.241.179:443
Referrer Policy: no-referrer-when-downgrade
HTTP/1.1 200 OK
Date: Tue, 31 Dec 2019 01:03:22 GMT
Server: Apache
Strict-Transport-Security: max-age=63072000; includeSubDomains
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,POST,HEAD,DELETE,PUT,OPTIONS,PATCH
Access-Control-Allow-Headers: authorization,x-requested-with,x-ohp-developer-api-key,content-type
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 336
Keep-Alive: timeout=15, max=98
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1
Sorry, I resolved it. Was passing wring syntax in the JSON body, stupid mistake.
my draft with big Attachment.
create draft with gapi.
update this draft add some big file.
upload draft rawdata by resumable upload.
when i start a resumable session, it return 404.
Array
(
[url] => https://www.googleapis.com/resumable/upload/gmail/v1/users/me/drafts/r3718017142990379914
[method] => post
[http_header] => Array
(
[0] => Authorization: Bearer ya29.****
[1] => Content-type: application/json
[2] => X-Upload-Content-Type: message/rfc822
)
[response] => HTTP/1.1 200 Tunnel established
HTTP/1.1 404 Not Found
X-GUploader-UploadID: AEnB2Up-CJW9XP4E84DqWjZhI_8-YFgWR47UNNfqGkmM2S5EBf3H5aGOcuwHzLd-4faoKAxd_qgaO5GInDUiJx6uua8JDwj4X0yLamxA--WySFB3ZZxw7YQ
Vary: Origin
Vary: X-Origin
Content-Type: text/html; charset=UTF-8
Content-Length: 9
Date: Fri, 18 Aug 2017 12:48:24 GMT
Server: UploadServer
Alt-Svc: quic=":443"; ma=2592000; v="39,38,37,35"
Not Found
[res_header] => HTTP/1.1 200 Tunnel established
[res_body] => HTTP/1.1 404 Not Found
X-GUploader-UploadID: AEnB2Up-CJW9XP4E84DqWjZhI_8-YFgWR47UNNfqGkmM2S5EBf3H5aGOcuwHzLd-4faoKAxd_qgaO5GInDUiJx6uua8JDwj4X0yLamxA--WySFB3ZZxw7YQ
Vary: Origin
Vary: X-Origin
Content-Type: text/html; charset=UTF-8
Content-Length: 9
Date: Fri, 18 Aug 2017 12:48:24 GMT
Server: UploadServer
Alt-Svc: quic=":443"; ma=2592000; v="39,38,37,35"
Not Found
[errno] => 0
[error] =>
)
so, is the draft can not edited using a resumable upload?
How can I edit a draft with a large attachment?
when you update draft, it must used put.
like:
PUT https://www.googleapis.com/upload/gmail/v1/users/me/drafts/r6052444812129220058
Application Setup
Client - AngularJS (hosted at client.domain.com)
API + SignalR - Hosted at api.domain.com
SignalR setup class
public void Configuration(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie
});
app.Map("/signalr", map =>
{
map.UseCors(CorsOptions.AllowAll);
var hubConfiguration = new HubConfiguration
{
EnableJSONP = true
};
map.RunSignalR(hubConfiguration);
});
}
And I do following from Authentication service
AuthenticationManager.SignOut();
List<Claim> claims = new List<Claim>();
claims.Add(new Claim(ClaimTypes.Name, myuserid));
ClaimsIdentity id = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie);
HttpContext.Current.GetOwinContext().Authentication.SignIn(new AuthenticationProperties() { IsPersistent = false }, id);
Authentication response looks like
HTTP/1.1 200 OK
Cache-Control: private
Pragma: no-cache
Content-Length: 556
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.5
Access-Control-Allow-Origin: *
Set-Cookie: ASP.NET_SessionId=pvasgf4q2klfbmk4oojqkxm5; path=/; HttpOnly
X-AspNet-Version: 4.0.30319
Set-Cookie: .AspNet.ApplicationCookie=1lBbz_FRNvxt1AhwkzZHFoiyhyZgsasNXStV3SbjQUHt0hqxTG--yXtjYNquB4zmQn-6M99pqHRPHaT4uf8g1JAnqg5WldD65IJ_FxYoEucf_WvV1fY4pwf774Cyo6fhI5nVk9Z6fdpjY422eo0GIibIMhaV9QvHNaiSsbFO0koT-CnhQuD5DED_418nP7m4FBbXdwIbFM_squ0bVYKXuB35jm57zVk9hUVWdlPmWxc; path=/; HttpOnly
X-Powered-By: ASP.NET
Date: Tue, 30 Dec 2014 00:20:29 GMT
When I the app makes request to signalr/negotiate, it receives 401 (unauthorized) because the cookie received in authentication response is not being sent with signalr request.
Is there anything I am missing?
UPDATE 1
All of above works fine when client and api are hosted in the same domain like this.
Client - www.domain.com/client
API - www.domain.com/api
UPDATE 2
Upon digging a little further, I realized that the issue is not related to signalr at all. I wrote a light client just to see if I can authenticate and follow that up with a simple get request. I hosted the client at api.domain.com/lightclient and made api requests to api.domain.com/api everything works. The following get request has the authentication cookie. However, when I moved the client to client.domain.com, browser removes the cookie.
I am trying to send a post request to my server but I keep recieving this error:
HTTP/1.1 400 Bad Request
Date: Sun, 11 Jan 2015 02:16:57 GMT
Server: Apache/2.4.4 (Win64) PHP/5.4.12
Content-Length: 325
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
Request header field is missing ':' separator.<br />
<pre>
cmd=connect&computer=derp\r\n</pre>
</p>
</body></html>
And here is my function for it.
void postReq(SOCKET sock, char *host, char *dat) {
char postDat[5001];
char postData[5001];
sprintf(postDat, "POST /search/api.php HTTP/1.0\r\n"
"Host: %s\r\n"
"Content-type: application/x-www-form-urlencoded\r\n"
"Conent-length: %d\r\n\r\n"
"%s\r\n", host, strlen(dat), dat);
puts(postDat);
send(sock, postDat, strlen(postDat)+1, 0);
}
Why am I recieving this error?