Using Epicor REST API to create contacts

I’m trying to create a customer using the Epicor REST API. I’m using the “Erp.BO.CustomerSvc” service to create the customer.
But I’m getting this error about “Object reference not set to an instance of an object.”

Below is the full response of the error

{
    "HttpStatus": 500,
    "ReasonPhrase": "REST API Exception",
    "ErrorMessage": "Object reference not set to an instance of an object.",
    "ErrorType": "System.NullReferenceException",
    "CorrelationId": "76f5b59f-c92d-4139-9c53-fd3becdd5a7a"
}

And here is what I’m passing as the payload :

{
    "Company": "xxx",
    "FirstName": "John",
    "LastName": "Doe",
    "ContactName": "John Doe",
    "CustNum": 0,
    "CustID": "12345",
    "CustomerName": "Light Company",
    "ContactCustomers": [
        {
            "Company": "xxx",
            "CustID": "1234",
            "CustNum": 0,
            "Name": "John Doe",
            "Address1": "22 man entrance",
            "City": "Ontario",
            "State": "Ontario",
            "Zip": "9093",
            "Country": "CA"
        }
    ]
}

Have a look at Epicor REST help. I don’t think you can add the customer and contacts by just calling CustomerSvc. I think you need CustCntSvc for contacts.

Also some of the fields you have there are wrong. Again, check the help for what fields you need. For customers, here’s something you can start with.

{
    "Company": "YourCmyID",
    "CustNum": 0,
    "CustID": "YourCustID",
    "Name": "Light Company"
}
3 Likes

Thank you @Dragos
I found the CustCntSvc, and it’s working fine now.

@Dragos I have this question to ask you—so, like, I have to create a customer to be able to add contacts for it, right? Or how does it work, please?

Yes, you need to add the customer first and then the contacts.

Alright I understand, thank you for the help.
I appreciate it. :fist_right::fist_left: