function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
John BroaddusJohn Broaddus 

Error Creating Task via REST API

I'm having issue creating a task via REST API and need some help as to point out what I may be doing wrong. My code is the following:

public class SalesForceEvent
{
    public SalesForceAccount Account { get; set; }
    public string Id { get; set; }
    public string AccountId { get; set; }
    public string OwnerId { get; set; }
    public string Subject { get; set; }
    public string Type { get; set; }
    public string Description { get; set; }
    public string Status { get; set; }
    public string ActivityDate { get; set; }
    public bool IsClosed { get; set; }
    public bool IsDeleted { get; set; }
    public string Priority { get; set; }
    public string WhoId { get; set; }
    public string WhatId { get; set; }

}

var uri = serviceUrl + "/services/data/v20.0/sobjects/Account/task/";

var task = new SalesForceEvent();
task.OwnerId = "XXXXXXXXX";
task.Account = acct;
task.ActivityDate = DateTime.Now.ToString();
task.Subject = "Call";
task.Type = "Call";
task.Status = "Completed";
task.Description = " A Call for this new task";
task.IsClosed = true;
task.Priority = "Normal";
task.WhoId = "";
task.WhatId = "XXXXXXXXX";


var ser = new JavaScriptSerializer();
var body = ser.Serialize(task);

var req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
req.Headers.Add("Authorization: OAuth " + SFHelper.SalesForceToken.access_token);
req.ContentType = "application/json";
req.Method = "POST";

byte[] data = System.Text.Encoding.ASCII.GetBytes(body);
req.ContentLength = body.Length;
var os = req.GetRequestStream();
os.Write(data, 0, data.Length);
os.Close();

WebResponse resp;

try
{
    resp = req.GetResponse();
}
catch (WebException ex)
{
    resp = ex.Response;
}

if (resp != null)
{
    HtmlGenericControl hgc = new HtmlGenericControl();
    StringBuilder sb = new StringBuilder();

    System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
    sb.Append(sr.ReadToEnd().Trim());

    hgc.InnerHtml = sb.ToString();
    plcResults.Controls.Add(hgc);

}

When making the call I get the following error message:

[{"errorCode":"NOT_FOUND","message":"Provided external ID field does not exist or is not accessible: task"}]

Any assistance is greatly appreciated.
Best Answer chosen by John Broaddus
SuperfellSuperfell
You're using the wrong URI, if you want to create a task, you need to use
var uri = serviceUrl + "/services/data/v20.0/sobjects/task/"


All Answers

SuperfellSuperfell
You're using the wrong URI, if you want to create a task, you need to use
var uri = serviceUrl + "/services/data/v20.0/sobjects/task/"


This was selected as the best answer
John BroaddusJohn Broaddus
Thanks. That was it.