REST API GET and POST on same call

I’m fairly new to REST-API and just have been using Postman for a couple of years. I know how to do a simple GET and a POST but that’s it. In our company website, we want to add the capability of having customers add their own contacts using API calls. First, we have to validate if the contact already exists in our Epicor and if the email address doesn’t exist, they would add it so I sent the GET and POST payload to the web team to make two separate calls and it’s been working fine. Well now, they are asking if we can do a GET and POST on the same call. Basically some kind of an if-then-else statement that IF the email address does not exist THEN add the contact, ELSE throw an error. Is this possible?

Thanks in advance.

you can do a patch… which is an update (or add if it doesn’t exist)

if you want to throw an error if it exists you can do that via BPM that checks for duplicates and throws an error on the Update / Post

Jose, sorry I guess my question wasn’t clear. To be more specific, we have an e-commerce site where we want customers who are logged in to be able to add company contacts. On a form on the site, customers would create a “New Contact” under their account. Our ecom team would like to make one single call to check (GET) and make sure if the contact does not exist in Epicor and if it’s not, then add (POST) the contact on the same call. If exists, GET returns a record, then the ecom team will display an error on our ecom website that the contact already exists. Currently, they are making two separate calls. You were saying, PATCH would be able to do this? We don’t want our customers to “update” and want them to only add. I hope this makes sense. If this is possible, is this easy enough to do or should we hire a consultant/programmer for this? Thank you.

No, a PATCH won’t do what you’re looking for either, I don’t think.

What you could do is wrap up your logic in an Epicor function that can then be called as a POST and do whatever you want. So you would accept whatever parameters you need (customer ID, contact name, whatever) through a POST, then the function you build in Epicor can check if the contact exists and return it without modifying it if it does or add it if it doesn’t. Functions work a lot like BPMs as far as building them goes, if you’re familiar with those, and they can be exposed through the REST API. If you’re not familiar with building BPMs, you might want to hire a consultant/programmer.

1 Like

What you are requesting is not possible.

Get is a read only operation
Post is a create operation

You can’t do what you want with a single call unless you make a custom endpoint (read Epicor function) as @ckoch suggested

Also if they are having to write the code anyway why does it matter?

Thank you Chris. This definitely gives me a starting point. I am familiar with building BPMs so I will check out the Functions side of Epicor.

Thank you also to all who responded with your comments and ideas. I really appreciate it a lot.

Any recommendations for a programmer/consultant we could hire to help us on this? Thanks.

I would recommend you reach out to a partner the folks at Six S are great, there are some other great partners on here too.
I can PM you their contact info if you’d like let me know.

I’d second SixS - but I am biased.