Quantcast
Channel: Sam's Activities
Viewing all articles
Browse latest Browse all 3363

Set CRM Lookup Value (another Entity) using WebAPI

$
0
0

I can create a New Entity but I'm trying to create an Entity with the lookup value to another Entity.  The code below works until I uncomment out the line to set the lookup value.  It always comes back as Bad request.

void Main()
{  
using(var webClient = new WebClient()){
    webClient.Credentials = new NetworkCredential("Username", "Password", "Domain");
    webClient.Headers.Add("OData-MaxVersion", "4.0");
    webClient.Headers.Add("OData-Version", "4.0");
    webClient.Headers.Add("accept", "application/json");
    webClient.Headers.Add("Content-Type","application/json");
    webClient.Headers.Add("Prefer", "odata.include-annotations=*");        

    webClient.BaseAddress = "dev.company.com/.../v8.0";

    var JO = new JObject();
    JO.Add("col_name","My Name");
    //JO.Add("col_contactid@odata.bind","/contacts(7266f26b-7105-e611-811e-005056b61789)");
    var dataString = JO.ToString();

    var responseString = webClient.UploadString("col_advisors", "POST", dataString);

    Console.WriteLine(webClient.ResponseHeaders.Get("OData-EntityId"));
}
}


Viewing all articles
Browse latest Browse all 3363

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>