+ Start a Discussion
mintotsaimintotsai 

Unable to call Apex Rest

In my org, I am using OAuth with Connected Apps and I have developed an Apex RestResource with a HttpGet method. Everything is working great on a dev org, however on a production org, I am getting an error, "We are down for maintenance. Sorry for the inconvenience. We'll be back shortly."

 

When using the Workbench, I can successfully call my RestResource. So I suspect I'm missing something really simple.

 

Any help would be really appreciated.

 

Here is the output from my curl command:

 

curl -k -v -X GET https://jasminepm-8890.cloudforce.com/services/data/v28.0/ -H "Authorization: OAuth MYTOKEN" -H "X-PrettyPrint:1" -H "Content-Type: application/json; charset=UTF-8" -H "Accept: application/json" -d "client_id=CLIENTID" -d "client_secret=CLIENTSECRET"
* About to connect() to jasminepm-8890.cloudforce.com port 443 (#0)
* Trying 96.43.146.90...
* connected
* Connected to jasminepm-8890.cloudforce.com (96.43.146.90) port 443 (#0)
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using RC4-MD5
* Server certificate:
* subject: C=US; ST=California; L=San Francisco; O=Salesforce.com Inc; OU=Applications; CN=*.na15.force.com
* start date: 2012-10-18 02:42:03 GMT
* expire date: 2015-10-18 02:42:03 GMT
* subjectAltName: jasminepm-8890.cloudforce.com matched
* issuer: O=Cybertrust Inc; CN=Cybertrust SureServer Standard Validation CA
* SSL certificate verify ok.
> GET /services/data/v28.0/ HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5
> Host: jasminepm-8890.cloudforce.com
> Authorization: OAuth MYTOKEN
> X-PrettyPrint:1
> Content-Type: application/json; charset=UTF-8
> Accept: application/json
> Content-Length: 129
>
* upload completely sent off: 129 out of 129 bytes
< HTTP/1.1 411 Length Required
< Server: scl
< Date: Fri, 09 Aug 2013 14:16:07 GMT
< Content-Type: text/html
< Content-Length: 1884
< X-Cnection: close
<
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<center>
<table bgcolor="white" style="align: center;">
<tbody>
<tr><td><br><br></td></tr>
<tr>

<td>
<table bgcolor="white" cellpadding="0" cellspacing="0" style="border:1px solid #ccc;" width="758">
<tbody>
<tr><td><br></td></tr>
<tr>
<td>
<div style="background-color: white; border: 1px solid #ccc; padding: 0px; margin-top: 10px; margin-bottom: 0px; margin-left: 10px; margin-right: 10px;">
<table bgcolor="white" cellpadding="0" cellspacing="0" width="758">
<tbody>

<tr>
<td><span style="font-family: Verdana; font-size: medium; font-weight: bold;">We are down for maintenance.</span><br><br>Sorry for the inconvenience. We'll be back shortly.</td>
</tr>
</tbody>
</table>
</div>

</td>
</tr>
<tr>
<td>
<span>
<table border="0" cellpadding="0" cellspacing="0" style="text-align: right;" width="100%">
<tbody>
<tr>
<td>

<span>
<span style="font-family: Verdana; font-size: smaller">Powered by <a href="http://force.com">force.com</a></span>
</span>
</td>
</tr>
</tbody>
</table>

</span>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr><td><br></td></tr>
<tr><td></td></tr>

<tr><td><br></td></tr>
</tbody>
</table>
</center>
<!-- Served by force.com -->
</body>
</html>
<!-- Generated Fri, 09 Aug 2013 14:16:07 GMT (scl) -->
* Connection #0 to host jasminepm-8890.cloudforce.com left intact
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):

mintotsaimintotsai

The solution for running curl turned out to be really stupid. I'm on a mac and the use of single quote without escaping the ! works.

 

curl -H "Content-Type: application/json; charset=UTF-8" -H 'Authorization: OAuth MYTOKEN' https://jasminepm-8890.cloudforce.com/services/data/v28.0/

Mat HamlinMat Hamlin
mintotsai, 

Were you ever able to identify the problem?
mintotsaimintotsai
If I recall correctly, it's been a while, the connected app needed to be in the managed package. Minto Founder | 512.553.5447 | mintotsai@jasminepm.com | http://www.linkedin.com/in/mintotsai
Amy HerzAmy Herz

For me, I was calling my @HttpGet method but putting params (id, firstName, lastName, etc) into the Body of my request, for GET they need to be in the params instead! If you make a call that includes more than the id for running a SOQL, you can use other params in the apex method similarly to this:

RestRequest req = RestContext.request;

String id = req.params.get('id');
String firstName = req.params.get('firstName');
String lastName = req.params.get('lastName');
String email = req.params.get('email');

        
if(!String.isEmpty(id)) {
    List<Lead> leadList = [SELECT id, firstName, lastName, email FROM Lead WHERE id = :id LIMIT 1];
}
happy coding :)