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
Sunny SSunny S 

Create a Case using Rest API

Hi all, 
I am still very new to Integration and API's, hence seek your help with the below query, please!

Q: We are looking to create Cases using REST Api, and got successfull in creating test cases uisng Post in Postman. 

User-added image

Problem: How do we populate the Contact Email and Contact Name for existing Contacts creating Tickets, so that Cases gets attached to the Conatct ?

Many thanks in advance!
Suraj Tripathi 47Suraj Tripathi 47
Hi Sunny S,
you can pass hardcore id in case if you want to provide a contact id to the case 

 
{
    "ContactId": "0032x000004fM8DAAU",
    "AccountId": "0012x0000082qL6AAI",
    "AssetId": null,
    "SuppliedName": null,
    "SuppliedEmail": null,
    "SuppliedPhone": null,
    "SuppliedCompany": null,
    "Type": "Mechanical",
    "Status": "New",
    "Reason": "Equipment Design",
    "Origin": "Web",
    "Subject": "Inadequate headroom with installation of aircon unit",
    "Priority": "Medium",
    "Description": null,
    "Comments": null
}


If this is helping you please right as the best answer.

Thanks 
Suraj Tripathi
Sunny SSunny S
Hi Suraj, thanks for your suggestion. 

I understand passing a Hardcoded Id can help me with Testing but - how would Case Creation work once we embed the code within another application?

Reasoning: Obvioously like standard web-to-case or Email-to-case, we would want the Contact Name and ContactEmail to populate with every created case. 
Would you be able to suggest anything here please?

Thanks again1
Suraj Tripathi 47Suraj Tripathi 47
Hi Sunny,
you can pass variable value in Body according to your data in case if you want to provide contactid to the case 
       
  
String jsonsString = '{'+
        '    \"contactid\" :' +'\"'+contactid+'\",'+
        '    \"AccountID\" :' +'\"'+AccountID+'\",'+
        .........
    .........
        '}';
        System.debug('jsonsString'+jsonsString);
         
        req.setBody(jsonsString);


 for your reference use the below link:
https://developer.salesforce.com/forums/?id=9060G000000I30hQAC

Thanks 
Suraj Tripathi
340