You need to sign in to do that
Don't have an account?
vino1.395228003587918E12
"[{\"message\":\"Session expired or invalid\",\"errorCode\":\"INVALID_SESSION_ID\"} in rest api
HttpClient updateclient = new HttpClient();
string requestMessage = "<root><name>test</name></root>";
HttpContent updatecontent = new StringContent(requestMessage, Encoding.UTF8, "application/xml");
//string requestMessage = "{\"Name\":\"DevForce20\"}";
//HttpContent updatecontent = new StringContent(requestMessage, Encoding.UTF8, "application/json");
string updateurl = serviceUrl + "/services/data/v25.0/sobjects/Account/";
//create request message associated with POST verb
HttpRequestMessage request1 = new HttpRequestMessage(HttpMethod.Put,updateurl);
//add token to header
request1.Headers.Add("Authorization", "Bearer " + oauthToken);
//return xml to the caller
request1.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
request1.Content = updatecontent;
HttpResponseMessage response1 = await updateclient.PutAsync(updateurl+"001O000000MPrtsIAD",request1.Content);
string resultipp = await response1.Content.ReadAsStringAsync();
Response.Write(resultipp);
return resultipp;
I got this error "[{\"message\":\"Session expired or invalid\",\"errorCode\":\"INVALID_SESSION_ID\"} .
If any one help me to resolve this.
string requestMessage = "<root><name>test</name></root>";
HttpContent updatecontent = new StringContent(requestMessage, Encoding.UTF8, "application/xml");
//string requestMessage = "{\"Name\":\"DevForce20\"}";
//HttpContent updatecontent = new StringContent(requestMessage, Encoding.UTF8, "application/json");
string updateurl = serviceUrl + "/services/data/v25.0/sobjects/Account/";
//create request message associated with POST verb
HttpRequestMessage request1 = new HttpRequestMessage(HttpMethod.Put,updateurl);
//add token to header
request1.Headers.Add("Authorization", "Bearer " + oauthToken);
//return xml to the caller
request1.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
request1.Content = updatecontent;
HttpResponseMessage response1 = await updateclient.PutAsync(updateurl+"001O000000MPrtsIAD",request1.Content);
string resultipp = await response1.Content.ReadAsStringAsync();
Response.Write(resultipp);
return resultipp;
I got this error "[{\"message\":\"Session expired or invalid\",\"errorCode\":\"INVALID_SESSION_ID\"} .
If any one help me to resolve this.
How are you setting Salesforce::LOGIN_BASE? It should be the instance_url you got along with access_token (something like na3.salesforce.com, not login.salesforce.com). See this cookbook recipe for more details: http://developer.force.com/cookbook/recipe/interact-with-the-forcecom-rest-api-from-php
https://developer.salesforce.com/forums?id=906F000000099x7IAA
Also see below,
http://salesforce.stackexchange.com/questions/21621/invalid-session-id-in-salesforce-restapi
Regards,
Ashish
Yes i added the instanceurl.My above code is
HttpClient hc = new HttpClient();
string consumerkey = "3MVG9Nvmjd9lcjRl5xQxpv_xyGmf8xD1xxozWzj3M2GOgmRau8SN1ElVxZ4Hqnl.5tcWCikg6.iqEVVRI3_R_";
string consumersecret = "4228649568468639459";
string concat = String.Concat(password, token);
HttpContent content = new FormUrlEncodedContent(new Dictionary<string, string>
{
{"grant_type","password"},
{"client_id",consumerkey},
{"client_secret",consumersecret},
{"username",username},
{"password",concat}
}
);
HttpResponseMessage obj1 = await hc.PostAsync("https://test.salesforce.com/services/oauth2/token", content);
string repstring = await obj1.Content.ReadAsStringAsync();
JObject obj = JObject.Parse(repstring);
string oauthToken = null;
string serviceUrl = null;
string session = null;
oauthToken = (string)obj["access_token"];
serviceUrl = (string)obj["instance_url"];
session = (string)obj["signature"];
HttpClient updateclient = new HttpClient();
string requestMessage = "<root><name>test</name></root>";
HttpContent updatecontent = new StringContent(requestMessage, Encoding.UTF8, "application/xml");
//string requestMessage = "{\"Name\":\"DevForce20\"}";
//HttpContent updatecontent = new StringContent(requestMessage, Encoding.UTF8, "application/json");
string updateurl = serviceUrl + "/services/data/v25.0/sobjects/Account/";
//create request message associated with POST verb
HttpRequestMessage request1 = new HttpRequestMessage(HttpMethod.Put,updateurl);
//add token to header
request1.Headers.Add("Authorization", "Bearer " + oauthToken);
//return xml to the caller
request1.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
request1.Content = updatecontent;
HttpResponseMessage response1 = await updateclient.PutAsync(updateurl+"001O000000MPrtsIAD",request1.Content);
string resultipp = await response1.Content.ReadAsStringAsync();
Response.Write(resultipp);
return resultipp;
The code looks good and did this solve your issue here?
Reply back if you have any further issues, we will try our best.
Regards,
Ashish
No i didnt got the result...... Please give some ideas.........
Are you able to save the code?
If you are able to save but failing at run time, Enable debug logs and monitor the logs.
Regards,
Ashish
I am able to save the code.
But i got the same error.
How are you setting Salesforce::LOGIN_BASE? It should be the instance_url you got along with access_token (something like na3.salesforce.com, not login.salesforce.com). See this cookbook recipe for more details: http://developer.force.com/cookbook/recipe/interact-with-the-forcecom-rest-api-from-php
See the below thread for more information,
https://developer.salesforce.com/forums?id=906F000000099x7IAA
Also see some more threads with Same issue,
http://salesforce.stackexchange.com/questions/21621/invalid-session-id-in-salesforce-restapi
http://stackoverflow.com/questions/6095352/salesforce-rest-api-invalid-session-id-error
Regards,
Ashish
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, fullRequest);
request.Headers.Add("Authorization", "Bearer " + oauthToken);
request.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
request.Content = new StringContent(caseJSON, Encoding.UTF8, "application/json");
HttpClient postClient = new HttpClient();
HttpResponseMessage result = await postClient.SendAsync(request);
string caseResult = await result.Content.ReadAsStringAsync();