+ Start a Discussion

How to retrieve CSRF token from form

Hi Developers,

I am attempting to make a request to the endpoint /oppitm/lineitemsort.jsp from a visual force page to sort OLIs. However, it is my understanding that in order to make post request like this I will need the CSRF token present in the request. I am trying to do this but I am having difficutly getting the correct token. I try to retrieve the token with the following ajax request:
            }).done (function(data){
                var token=data.substring(pos_start+key_start.length,pos_end);

But I continually get redirected to "Unable to access page." when using the CSRF token that is returned.  My understanding is that Visual Force will store the CSRF token in the form under an input with id "com.salesforce.visualforce.ViewStateCSRF" following a post, so I have been trying to get the token that way. But all attempts to do so result in an empty value in that element. Any ideas when that is appending to the form and how I can get it?
Mitesh SuraMitesh Sura
You may want to follow this thread: https://developer.salesforce.com/forums/ForumsMain?id=906F00000008zkRIAQ
@Kdavis, Were you able to get the solution? 
@Mitesth, i tried to follow the thread mentioned above, but its stil not working for me.