Tom Knowlton
asked on
No HTTP resource was found that matches the request URI
I need help troubleshooting / fixing the problem:
The request in POSTMAN:
The response in POSTMAN:
The underlying C# Controller ( NOTE: The breakpoints I set in the controller constructor are hit ... the ones in CreateWorkOrder are not )
EDIT:
I came across WebApiConfig.cs which looked helpful and "Route" like:
What is this part:
routeTemplate: "api/{controller}/{id}",
and what is it describing? The "api" is confusing to me because it does not show up in the URL (is not part of my request)
The request in POSTMAN:
POST /sforce/createworkorder HTTP/1.1
Host: localhost:29081
Authorization: Bearer vvThd_mOentifQX YOU GET THE IDEA eMARduXY2E2uJ_pw2QDYumZ7YdKIyYSpeMvPBIFEMMi-P3jhKWthLATNcdX5HuDqyUdq30QYiPbJgRLkoYHjB4NhuT8UoAsagoRcToDTSQuIouWred1cs6dm8jUzqLa-lA2Wp8YtM3srVHOgNtSj5uRKfTZc7_5lZ4FWx8wFe_ESqizEdtC1tPXxHxTxXKw
Content-Type: text/plain
{
request : '{"dealerInfo":{"connId":"1730","dealerId":"40000148","dealerName":"Clear Home","dealerCode":"PFL7E","corpId":"60425","storeId":"1791538"},"orderInfo":{"orderNumber":"DS6665I23389211","orderDate":"2020-03-23T00:00:00Z","customerInfo":{"custType":"Residential","firstName":"Jaeff","lastName":"Srber","phone":"972-555=9205","altPhone":"","email":"uglx9@gmail.com","address1":"1725 WILLOW CRK","address2":"","city":"MESQUITE","state":"TX","zip":"75181-1590"},"videoInfo":{"provider":"DTV","componentCode":"ATT-COMP-DTV-ULT-ALL-INCL","package":"DIRECTV ULTIMATE All Included","orderNumber":"99-
TRUNCATED
VR with a Genie. Enjoy a full HD DVR experience in every room. Record any 5 shows at the same time, all in HD. Record up to 200 hours in HD.' style='padding-left:2px; padding-right:2px'>Genie</td><td class='emphasis' align='right'><span id='genieValue' style='color:green'>$0.00</span></td></tr><tr><td id='3genieminis' title='3 Genie Minis' style='padding-left:2px; padding-right:2px'>3 Genie Minis</td><td class='emphasis' align='right'><span id='3genieminisValue' style='color:green'>$0.00</span></td></tr><tr><td id='deliveryandhandling' title='DeliveryzderComments":{"value":""},"orderNotes":{"value":""}}}'
}
The response in POSTMAN:
{
"Message": "No HTTP resource was found that matches the request URI 'http://localhost:29081/sforce/createworkorder'.",
"MessageDetail": "No action was found on the controller 'Salesforce' that matches the request."
}
The underlying C# Controller ( NOTE: The breakpoints I set in the controller constructor are hit ... the ones in CreateWorkOrder are not )
using Clear.Core.Helpers;
using Clear.Core.Managers;
using NLog;
using Swashbuckle.Swagger.Annotations;
using System;
using System.Net;
using System.Web.Http;
using Clear.Core.Models.Salesforce;
using Clear.Core.Repositories;
using Clear.Core.Models.TransferModels;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
namespace ClearSync.API.Controllers
{
[RoutePrefix("sforce")]
public class SalesforceController : ApiController
{
private readonly Logger _logger;
private readonly ISalesforceManager _salesforceManager;
private readonly ISalesforceClientHelper _salesforceClientHelper;
private readonly ISalesforceRepository _salesforceRepository;
private readonly ITerritoryHelper _territoryHelper;
private readonly IPandoManager _pandoManager;
public SalesforceController(ISalesforceRepository salesforceRepository, ISalesforceClientHelper salesforceClientHelper, ITerritoryHelper territoryHelper, IPandoManager pandoManager)
{
_logger = NLog.LogManager.GetCurrentClassLogger();
_salesforceClientHelper = salesforceClientHelper;
_salesforceRepository = salesforceRepository;
_territoryHelper = territoryHelper;
_pandoManager = pandoManager;
}
[SwaggerOperation(Tags = new[] { "Salesforce" })]
[SwaggerResponse(HttpStatusCode.OK, "", typeof(SalesforceAppointmentResponse))]
[HttpPost, Authorize, Route("createworkorder")]
public IHttpActionResult CreateWorkOrder(string request)
{
try
{
Order o = new Order();
JObject jOrder = JObject.Parse(request);
o.OrderInfo = new OrderInfo();
o.DealerInfo = new DealerInfo();
o.OrderInfo.OrderNumber = (string)jOrder["orderInfo"]["orderNumber"].ToString();
o.OrderInfo.OrderDate = DateTime.Parse(jOrder["orderInfo"]["orderDate"].ToString());
o.OrderInfo.CustomerInfo = JsonConvert.DeserializeObject<CustomerInfo>(jOrder["orderInfo"]["customerInfo"].ToString());
o.OrderInfo.VideoInfo = JsonConvert.DeserializeObject<VideoInfo>(jOrder["orderInfo"]["videoInfo"].ToString());
o.OrderInfo.InternetInfo = JsonConvert.DeserializeObject<InternetInfo>(jOrder["orderInfo"]["internetInfo"].ToString());
o.OrderInfo.VoiceInfo = JsonConvert.DeserializeObject<VoiceInfo>(jOrder["orderInfo"]["voiceInfo"].ToString());
o.OrderInfo.WirelessInfo = JsonConvert.DeserializeObject<WirelessInfo>(jOrder["orderInfo"]["wirelessInfo"].ToString());
o.OrderInfo.AgentInfo = JsonConvert.DeserializeObject<AgentInfo>(jOrder["orderInfo"]["agentInfo"].ToString());
string responseBack = _salesforceManager.CreateWorkOrder(o).Result;
return Ok(new SalesforceAppointmentResponse()
{
WorkOrderId = responseBack
});
}
catch (Exception ex)
{
return BadRequest("Unable to create work order " + ex.ToString() + ex.InnerException.Message );
}
}
}
}
EDIT:
I came across WebApiConfig.cs which looked helpful and "Route" like:
using System.Web.Http;
using ClearSync.API.Helpers;
using Newtonsoft.Json;
namespace ClearSync.API
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
config.MessageHandlers.Add(new CustomLogHandler());
var jsonFormatter = config.Formatters.JsonFormatter;
jsonFormatter.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
What is this part:
routeTemplate: "api/{controller}/{id}",
and what is it describing? The "api" is confusing to me because it does not show up in the URL (is not part of my request)
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
using Salesforce.Force;
using System.Threading.Tasks;
using Clear.Core.Helpers;
using Salesforce.Common;
namespace SalesforceManagerNS.Helpers
{
public class SalesforceClientHelper : ISalesforceClientHelper
{
public SalesforceClientHelper()
{
GetSalesForceClientAsync();
}
private static AuthenticationClient _authClient = new AuthenticationClient();
private ForceClient _client;
public AuthenticationClient AuthClient()
{
return _authClient;
}
public ForceClient SFClient()
{
return _client;
}
public void GetSalesForceClientAsync()
{
GetAuthClient();
_authClient.ApiVersion = "v48.0";
_client = new ForceClient(_authClient.InstanceUrl, _authClient.AccessToken, _authClient.ApiVersion);
}
public void GetAuthClient()
{
string ConsumerKey = "3MVsdfgfdsgfdsgfsadfds5H8iJtfcfwH059";
string ConsumerSecret = "3C5FFA07C3F4F111ECAA3FC2FB12C8F1CBF04";
string Username = "tofdhdgfhdgfm@tufhgdfghgfdy.com";
string Password = "Tgdgfsdgfsdfdfghce.com/services/oauth2/token";
_authClient.UsernamePasswordAsync(ConsumerKey, ConsumerSecret, Username, Password, url).Wait();
}
}
}
ASKER
how does this fit into the syntax above for API controller id?