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
SamiraSamira 

Integration between web application and salesforce - how to do a simple POST call - REST API

Hi,
 
I want to integrate a web applciation with salesforce. My prefered way it through REST API to do a post call.


Here is the scenario I am trying to achive:


I have an Id, I want to query a companies salesforce database and look for an existing record that matches the given Id. If it is found, I would like to update this existing record. If there was no match, I would like to create a new record in their database based on that Id.
 
How can I achive this? Where can I get token/auth for API calls? How can I make these API calls? What are the steps I have to take?
 
I have already signed up for developers edition.

I am not looking for C#/JAVA/... codes. I just want to do a simple Post call while passing that Id.
 
I would greatly appriciate any help you can give me on this matter.

Prateek Singh SengarPrateek Singh Sengar
Hi Samira,
Please see the post from Jeff D on HTTP callout from apex using POST, this should provide you with a good understanding on how to make the callouts.

http://blog.jeffdouglas.com/2009/03/16/restful-web-service-callout-using-post/

Now based on your requirement, you will require multiple callouts.
1) Callout to REST service for query
2) Callout to REST serivce for update or insert based on result of 1st callout.

For basic auth callout please see the below article
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_httprequest.htm

Hope this helps
SamiraSamira
Hi Prateek,

Thank you for your reply.

I would like to avoid using Apex.
Could you answer the following questions please:

1- If I want to integrate with Salesforce in .NET C#, is there anyway to avoid using SOAL API? I really would like to use REST.
This site gives info about SOAP and has no information about REST API integrations.
https://developer.salesforce.com/page/Integrating_Force.com_with_Microsoft_.NET

2-  For API calls, is there a way to integrate with salesforce through token/refresh token and not using username password for authentication?

Thanks!
 
Prateek Singh SengarPrateek Singh Sengar
Hi samira,
I dont have knowledge in .NET or C# however i am sure it can be done. Please find below an article that connects with salesforce using REST API from JAVA.

https://developer.salesforce.com/page/Getting_Started_with_the_Force.com_REST_API
SamiraSamira

Hi Prateek,

Thank you for the link.

As far as I could tell, there are two ways to authenticate with salesforce:
One is username/password and the other is using OAuth 2.0.

Based on what I understood, for OAuth 2.0 I 'have to' create a new Connected App in salesforce UI.

Is there anyway to by pass this step and get authenticated without creating a new App within customer’s environment?
Is it true that we don't need to create App if we use username and password authentication?

Please advice!

​Thanks

 

Prateek Singh SengarPrateek Singh Sengar
Hi Samira,
Oath 2.0 based connection will request the user to accept connection for your application. This in turn will create a connected app in the target enviornment (for managed packages). However the admin of the target enviornment have control over the permissions that can be granted to the app. So thats a good thing.
https://developer.salesforce.com/page/Digging_Deeper_into_OAuth_2.0_on_Force.com
For username and password based authentication (without Oauth) you wont required connected app.
Peter GruhlPeter Gruhl
Hi Samira,
It's been a while since your question.  I'd like to leave a few comments for others that my be viewing this thread in the future.
The Salesforce REST API does not support login.  You need some other way to Authenticate as a valid Salesforce User, sometimes referred to as the "Integration User".  You can use any development environment you like: most commonly I see C#, and Java.  The initial signon is often done using SOAP, then the access_Token is used in the REST calls.  Registering the App ahead of time allows the alternative of using OAuth Consumer Key / Consumer Secret in place of User / Password authentication.  By the way, be advised that you will need to append the Security Token on the end of the Password when using User / Password credentials.

Your comment says you want to lookup a Salesforce record up by Id.  That implies you have a specific Id for that Salesforce Org.  If it is *not* found, you then want to insert the record "passing in that Id".  Know that Ids in Salesforce are System generated at the time of insert.  You will not be able to pre-specify the Id of a new record.  An alternative is the Upsert command, roughly equivalent to the PUT REST command.  If the record is there, it updates it, if not the record is automatically inserted. If you can work this out, it will save you the initial read.  But how?  Look into doing the Upsert utilizing an External ID, an alternative to using the actual ID.  That will allow you to use the Upsert DML command alone, and not have to do the initial read.  Upsert has some additional features that help prevent duplicates, e.g. it will return an error of more than one record is found in Salesforce.  On update, only the changed fields need to be populated -- there is no specific need to do a read first.