Posts

Showing posts with the label API

Posting out to 3rd party API

Example of taking data in the form of a Model from your site and sending it out somewhere else and getting back a httpresponsemessage. [HttpPost]   public HttpResponseMessage Post(Appt_Model_DTO  appt)         { >>>>You could eliminate this portion   if (ModelState.IsValid)             { //not necessary but you can run some checks to make sure the data is good //that the model is valid and there is not  //you posted this data from your MVC site to your API Controller //Now we are going to send it off to a third party site                 if (appt.ID == null) {                     appt.ID = my_provider.getRecordwithSameIdentity(appt.AccountCode);                 }                 appt.StartDateTime = DateTime.Now;   ...

Calling an External Web API from Controller - No Jquery

The challenge is to call an external API and put it into a model you can use. The example below has a simple model STAPI_DTO which has two string fields - one of which is a client key which is what I am after string serviceURL = "https://someurl" + appt.POSID; var client = new WebClient(); //where STAPI_DTO is my model  STAPI_DTO st = new STAPI_DTO();   STAPI_DTO result = JsonConvert.DeserializeObject (client.DownloadString(serviceURL));  string clientkey = result.APIKEY;