I am new with Acumatica Web Service Endpoints. I have used couple of examples of how I can get the data from certain tables, but the thing is that I want to make one new API link, which will be used as POST from one external app.
When the data is sent, my Graph would take the data, and use the existing DACs to save the sent data....I already have all the DACs so in general I would need to :
provide a link for external POST call
when called, to authenticate the user and in case that the authentication is ok
to receive the data, and convert it into my objects....
save the data and the attachments
logout
Is Acumatica that much flexible ? When the data is received, the easiest way is to use the Newtonsoft json to convert into object...but that is also not the case here....
I am pretty confused which approach I can use....any suggestions?
All of this methods I have used within simple console app...but Acumatica is much more complex....
You can implement the IWebhookHandler of Acumatica for the creation of the Incoming Webhooks.
Below is a demo implementation of that interface
using Newtonsoft.Json;
using PX.Data;
using PX.Data.Webhooks;
using System;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Results;
namespace DemoIncomingWebhook
{
public class MyDemoWebhook : IWebhookHandler
{
[Serializable]
public class MyDemoWebhookResponse
{
public string Status { get; set; }
public string Mesage { get; set; }
}
public async Task<IHttpActionResult> ProcessRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
// In this method, the developer needs to process a request from an external application,
// including the following:
// • Process authentication information in the request
// • Transform the data in external format to the data that can be saved in Acumatica ERP
// • Invoke graph methods that save the data in Acumatica ERP
return await Task.FromResult(new JsonResult<MyDemoWebhookResponse>(new MyDemoWebhookResponse
{
Status = "Success",
Mesage = "Demo webhook worked!"
}, new JsonSerializerSettings(),Encoding.ASCII,request));
}
}
}
Then you need to register your webhook on the Webhooks page, Acumatica will generate the URL when the record is saved.
After that, you can use webhook and send a POST request to it
Related
We are using the forge-api-java-client. There is an issue in Model Derivatives getManifest call.
The response fails mapping with a single Message String being returned instead of the expected String Array.
Have switched to using local build of the jar, change in file Message.java to include an alternative constructor for the class setMessage
public void setMessage(String message) {
List<String> messages = new ArrayList<>();
messages.add(message);
setMessage(messages);
}
Could this change be merged into the project.
We'll check it, but as of today, that package is just under maintenance. You are welcome to submit a PR.
I am using the following code to generate a JSON for a Salesforce custom object called Resource Booking. How can I "run" the file (or call responseJSON) so that when I input the custom URL (in the first comment) it jumps to a page similar to this example web page? https://www.googleapis.com/customsearch/v1?json
Here is my code:
#RestResource(urlMapping='/demo/createTask/*') //endpoint definition > {Salesforce Base URL}/services/apexrest/demo/createTask/
global class ResourceBookingTransfer {
public List<Resource_Booking__c> resourceBookingList{get; set;}
public ResourceBookingTransfer(ApexPages.StandardController controller) {
//getResourceBookingList();
}
#HttpGet //HttpGet request
global static responseWrapper getResourceBookingList() {
responseWrapper responseJSON = new responseWrapper(); //responseWrapper object for API response
responseJSON.message = 'Hello World';
return responseJSON; //return the JSON response
//resourceBookingList = Database.query('SELECT Booking_ID__c, Booking_Name__c, Start_Date_Time__c, End_Date_Time__c, Resource__c FROM Resource_Booking__c');
}
//wrapper class for the response to an API request
global class responseWrapper {
global String message {get;set;} //message string
//constructor
global responseWrapper() {
this.message = '';
}
}
}
To just test it - it might be simplest to use https://workbench.developerforce.com. There's "REST explorer" menu in there. Your code should be available under resource similar to /services/apexrest/demo/createTask.
Why that url? Read https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_code_sample_basic.htm
Once you're happy with this manual testing - you can try to do it from outside workbench. Workbench logs you in to SF and passed header with valid session id in the background. If you want to call your service from another website or mobile app - you need to perform login call first, get the session id and then run your code. There are several OAuth flows you can use to do this depending in what your app needs, maybe start with this one: https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_username_password_oauth_flow.htm
I'm working on a system that sends a simple JSON object to a C# .NET Web API in the form:
{property1: "string1", property2: "string2"}
I want to receive this JSON into the web api. I can't initially use a custom object when I receive the JSON into the web API (because the system I'm working writes stuff into the DB automagically, and for this to work, only the built-in C# types can be used at the point that data reaches the web api).
The system doesn't utilise JQuery, so that's not an option. How can I accept this JSON into the Web API?
You could make use of dynamic type:
[Route("your route")]
[HttpPost]
public IHttpActionResult Post([FromBody]dynamic properties)
{
var property1 = properties["property1"];
var property2 = properties["property2"];
//your code
}
or
[Route("your route")]
[HttpPost]
public IActionResult Post([FromBody]object properties)
{
var property1 = (properties as dynamic)["property1"];
var property2 = (properties as dynamic)["property2"];
//your code
}
I'm kinda stuck on this topic.
This is what i already found out.
A good tutorial was :
Using MySQL in Spring Boot via Spring Data JPA and Hibernate
http://blog.netgloo.com/2014/10/27/using-mysql-in-spring-boot-via-spring-data-jpa-and-hibernate/
I also found some information how to make single page application with hsqldb.
But i really want to create something that permanent saves the users data to the database using mysql.
But in order to use angular http i need json. Can i convert the urls like
/create?email=[email]&name=[name]
To json how should i proceed. Does anyone knows good tutorials on this. Or are there better way's to proceed.
The simplest/handy way to consuming JSON with Spring Boot is using a Java class that resembles your JSON (https://stackoverflow.com/a/6019761).
So, you can follow the tutorial you linked, then use a controller like this one to handle JSONs:
#RestController
public class UserController {
#RequestMapping(
value = "/user/create",
method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> createUser(#RequestBody User user) {
try {
// Handle the User object here
userDao.save(user);
}
catch (Exception ex) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
return new ResponseEntity<>(HttpStatus.OK);
}
// ...
}
Receiving a JSON like this (at the url /user/create):
{email: "john#doe.com", name: "John Doe"}
An user will be saved in your database.
Responding with JSON
Moreover, if you want to send a response as JSON from your controller you should create a java object then send it back as response, within the ResponseEntity object.
For example, suppose to have this class:
public class SuccessDto {
private String success;
public SuccessDto(String success) {
this.success = success;
}
}
You can change your controller in this way:
public ResponseEntity<SuccessDto> createUser(#RequestBody User user) {
// ...
return new ResponseEntity<>(
new SuccessDto("true"),
HttpStatus.OK
);
}
and you will have this JSON as response
{success: "true"}
if you have already managed to use it with HSQLDB, it's juste a matter of database properties (like the JDBC URL) and schema initialization.
Can you provide the code sample of the controller, how you save the data (via a Repository or a simple DAO ?) and the application.properties
I am a beginner in web api asp.net MVC and I have a problem.
I have a class that I will use in web api HttpGet and HttpPost:
public class Credit
{
public string Log {get; set;}
public string Pas {get; set;}
}
In the example API controller I have:
[HttpGet]
public void Login (Credit credit)
{
}
[HttpPost]
public void Login (Credit credit)
{
}
Tests of these methods in RestConsole in Google Chrome, sending json data:
{"Log", "test", "Pas": "test"}
When debugging these methods, I see that HttpPost is working properly and parameter of "credit" is filled with properties.
However HttpGet is not working properly, the object is not filled property, it is NULL.
Can someone explain to me this situation and how can I get the complete object in the HttpGet?
This is because of how Web API creates parameter values from the HTTP request.
By default, if the parameter is a "complex" type (such as your Credit class), Web API gets the parameter value from the body of the request. If the parameter is a "simple" type (e.g., int or string), then Web API gets the value from the request URI.
However, HTTP GET requests cannot have a request body. So by default you can't pass a complex type to a Web API "GET" method.
You can read more here: http://www.asp.net/web-api/overview/formats-and-model-binding/parameter-binding-in-aspnet-web-api
In any case, for a Login method, you probably should use a POST request, not a GET request.