As a followup of windows curl authentication error, i'm doing the tutorial on https://trailhead.salesforce.com/content/learn/modules/apex_integration_services/apex_integration_webservices?trail_id=force_com_dev_intermediate.
This part is on 1:38:00, in that embeded video
i can now authenticate with curl, and get
{
"access_token":"cccccccccc",
"instance_url":"https://my.instance-dev-ed.my.salesforce.com",
"id":"https://login.salesforce.com/id/xxx/xxx",
"token_type":"Bearer",
"issued_at":"xxxx",
"signature":"xxxx"
}
now when i make the request, with
curl https://my.instance-dev-ed.my.salesforce.com/services/apexrest/Cases/5005J000001PsVuQAK -H "Authorization: Bearer cccccccccc" -H "X-PrettyPrint:1"
where 5005J000001PsVuQAK is the id of a case. I think this syntax seems ok, and similar to her code
i have windows 10 and curl seems fine:
# running
curl --version
# returns
curl 7.55.1 (Windows) libcurl/7.55.1 WinSSL
Release-Date: [unreleased]
Protocols: dict file ftp ftps http https imap imaps pop3 pop3s smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile SSPI Kerberos SPNEGO NTLM SSL
Yet i get no response: no errors, nothing. Any clues?
edit 1: adding the -v option, from kurunve:
* Trying 85.222.146.235...
* TCP_NODELAY set
* Connected to playful-shark-qc4wfn-dev-ed.lightning.force.com (85.222.146.235) port 443 (#0)
* schannel: SSL/TLS connection with playful-shark-qc4wfn-dev-ed.lightning.force.com port 443 (step 1/3)
* schannel: checking server certificate revocation
* schannel: sending initial handshake data: sending 212 bytes...
* schannel: sent initial handshake data: sent 212 bytes
* schannel: SSL/TLS connection with playful-shark-qc4wfn-dev-ed.lightning.force.com port 443 (step 2/3)
* schannel: failed to receive handshake, need more data
* schannel: SSL/TLS connection with playful-shark-qc4wfn-dev-ed.lightning.force.com port 443 (step 2/3)
* schannel: encrypted data got 3934
* schannel: encrypted data buffer: offset 3934 length 4096
* schannel: sending next handshake data: sending 126 bytes...
* schannel: SSL/TLS connection with playful-shark-qc4wfn-dev-ed.lightning.force.com port 443 (step 2/3)
* schannel: encrypted data got 51
* schannel: encrypted data buffer: offset 51 length 4096
* schannel: SSL/TLS handshake complete
* schannel: SSL/TLS connection with playful-shark-qc4wfn-dev-ed.lightning.force.com port 443 (step 3/3)
* schannel: stored credential handle in session cache
> GET /services/apexrest/Cases/ HTTP/1.1
> Host: playful-shark-qc4wfn-dev-ed.lightning.force.com
> User-Agent: curl/7.55.1
> Accept: */*
> Authorization: Bearer <token remove for security>
> X-PrettyPrint:1
>
* schannel: client wants to read 102400 bytes
* schannel: encdata_buffer resized 103424
* schannel: encrypted data buffer: offset 0 length 103424
* schannel: encrypted data got 609
* schannel: encrypted data buffer: offset 609 length 103424
* schannel: decrypted data length: 580
* schannel: decrypted data added: 580
* schannel: decrypted data cached: offset 580 length 102400
* schannel: encrypted data buffer: offset 0 length 103424
* schannel: decrypted data buffer: offset 580 length 102400
* schannel: schannel_recv cleanup
* schannel: decrypted data returned 580
* schannel: decrypted data buffer: offset 0 length 102400
< HTTP/1.1 302 Moved Temporarily
< Date: Mon, 21 Jun 2021 10:58:14 GMT
< Strict-Transport-Security: max-age=31536001; includeSubDomains
< 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=k6kItdJ_EeuhqRMSddwlGg; domain=.force.com; path=/; expires=Tue, 21-Jun-2022 10:58:14 GMT; Max-Age=31536000
< Location: my.domain-ed.my.salesforce.com/services/apexrest/Cases/
< Content-Length: 0
<
* Connection #0 to host my.domain-dev-ed.lightning.force.com left intact
Edit 2: i implemented the other methods in the tutorial, but here, i only use the @HttpPut:
@RestResource(urlMapping='/Cases/*')
global with sharing class CaseManager {
/*
other methods also implemented for:
@HttpDelete, @HttpPost, @HttpPatch, @HttpGet
*/
@HttpPut
global static ID upsertCase(
String subject, String status, String origin, String priority, String id
) {
Case thisCase = new Case(
Id = id,
Subject = subject,
Status = status,
Origin = origin,
Priority = priority
);
upsert thisCase;
return thisCase.Id;
}
}
To understand if it's something to to with my authentication or Apex, i used Postman, with the sames access, URL, etc:
that returns me the Expected JSON. Notice its the same id and REST path:
{
"attributes": {
"type": "Case",
"url": "/services/data/v52.0/sobjects/Case/5005J000001PsVuQAK"
},
"CaseNumber": "00001000",
"Subject": "Starting generator after electrical failure",
"Status": "Closed",
"Origin": "Phone",
"Priority": "High",
"Id": "5005J000001PsVuQAK"
}
edit 3: reviewing function names and HTTP methods. Sorry identigral, i don't get what you mean:
@HttpGet global static Case getCaseById(){
// returns Case, with list of associated contacts
}
@HttpPost global static ID createCase(){
// insert new case, returns thisCase.Id;
}
@HttpDelete global static void deleteCase() {
// deletes case, no return
}
@HttpPut global static ID upsertCase(){
// upserts cade, returns thisCase.Id;
}
@HttpPatch global static ID updateCaseFields() {
// updates fields, returns thisCase.Id;
}
-v
parameter return?/services/apexrest
is for custom Apex REST services. Your custom Apex REST service as shown handles a PUT request but your question shows GETs.playful-shark-qc4wfn-dev-ed.lightning.force.com
it will perform a redirect (301) which could be your issue in cURL