I'm having a problem accessing the REST API from a VF page. Basically, the request performs OK, except for the parameters, which are not being set/do not arrive on the endpoint.

I'm using forcetk to avoid the cross domain issue. This is the relevant VF code:

<apex:includeScript value="{!URLFOR($Resource.MyResource, 'jquery-1.9.1.min.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.MyResource, 'forcetk.js')}"/>

<script type="text/javascript">
    $(document).ready(function() {

        var forceTKClient = new forcetk.Client();

            function(data, textStatus, jqXHR) {
                console.log('SUCCESS - ' + data);
            function(jqXHR, textStatus, errorThrown) {
                console.log('ERROR - ' + textStatus);

And this is the Apex controller for the REST resource:

global with sharing class MyRestResource {

    global static Map<String, String> doGet() {

        Map<String,String> res = new Map<String,String> {
            'received' => 'yes'

        return res;


My custom REST method is reached correctly, and the response from it is returned correctly, but the parameters do never get to my custom REST method. I.e., the response received on the JS callback is

{received: "yes"}

whereas it should be

{received: "yes", myParameter: "myValue"}

Inspecting the request sent from the browser I see that the endpoint is


"myParameter" isn't present anywhere on the browser request.

Any hint?

Thanks in advance,

  • 1
    What is the whole point of creating the REST Class? are you trying to render data on the VF page, have you looked at Jscript remoting as an alternative? – Rao May 9 '13 at 18:01
  • boards.developerforce.com/t5/APIs-and-Integration/… are u the same guy @rich rosen – Rao May 9 '13 at 20:19

I think apexrest() is expecting a string, rather than an object for the payload parameter. Pass the payload as JSON.stringify({'myParameter':'myValue'}) and it should work.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.