Often we want to create an item AND set the CustomFieldValue object initially without having to log into Project Insight and do it manually.
The easiest way to do this:
C#
var client = new RestClient("https://{YOUR_DOMAIN}/api/project/"); var request = new RestRequest(Method.POST); request.AddHeader("postman-token", "5203eb17-247c-cbce-6a6e-d0a68f0c5e9f"); request.AddHeader("cache-control", "no-cache"); request.AddHeader("content-type", "application/json"); request.AddHeader("api-token", "{YOUR_API_TOKEN}"); request.AddParameter("application/json", "{\r\n\"Name\":\"Project Web Api 822b\",\r\n\"ItemContainer_Id\":\"ef076503622a4a129d2f151cc4372830\",\r\n\"ItemNumber\":11,\r\n\"Description\":\"Created using Project Insight Web Api (REST) 822b\",\r\n\"ProjectMode\":1 ,\r\n\"CustomFieldValue\": {}\r\n}\r\n\r\n", ParameterType.RequestBody); IRestResponse response = client.Execute(request);
cURL
curl -X POST \ https://{YOUR_DOMAIN}/api/project/ \ -H 'api-token: {YOUR_API_TOKEN}' \ -H 'cache-control: no-cache' \ -H 'content-type: application/json' \ -H 'postman-token: 29e078c4-5578-b099-0305-2f497fab7a62' \ -d '{ "Name":"Project Web Api 822b", "ItemContainer_Id":"ef076503622a4a129d2f151cc4372830", "ItemNumber":11, "Description":"Created using Project Insight Web Api (REST) 822b", "ProjectMode":1 , "CustomFieldValue": {} } '
HTTP Request
POST /projectinsight.webapp/api/project/ HTTP/1.1 Host: dev22.sandbox.projectinsight.net api-token: {YOUR_API_TOKEN} Content-Type: application/json Cache-Control: no-cache Postman-Token: bf79c352-821b-ad06-3c90-1d6d1633f5d2 { "Name":"Project Web Api 822b", "ItemContainer_Id":"ef076503622a4a129d2f151cc4372830", "ItemNumber":11, "Description":"Created using Project Insight Web Api (REST) 822b", "ProjectMode":1 , "CustomFieldValue": {} }
Make sure to create a CustomFieldValue object and set it on the object, otherwise, you'll have to make another rest call in order to update the object by setting the CustomFieldValue_Id property.
Happy coding!
Comments
0 comments
Please sign in to leave a comment.