Acumatica API get all attachments - api

I have a problem while trying to get attachment from ACUMATICA through API service.
As the example in http://acumaticaopenuniversity.com/pdf/T210_Acumatica_Web_Services.pdf page 36
Example code here
But I don't know how many files here and what are their names? How can I get all attachment of this entity?
Thank in advance.

The contract based web service API has a straightforward GetFiles interface for getting all files of an entity. When you don't have special requirements that forces you to use the screen based web-service API, I'd recommend you use the contract based one.
Interface:
File[] GetFiles(Entity entity)
Usage pseudo-code:
using (DefaultSoapClient soapClient = new DefaultSoapClient())
{
soapClient.Login("username", "password", "CompanyLoginName", null, null);
File[] files = soapClient.GetFiles((Entity)soapClient.Get(new Entity { EntityIntField = new IntSearch { Value = 1 } }));
}
Contract based web service API reference:
http://acumaticaopenuniversity.com/courses/i210-contract-based-web-services/

Related

Managing CosmosDb Session Consistency levels with Session Token in web environment

My environment is ASP.NET Core 2.x accessing CosmosDb (aka DocumentDb) with the .NET SDK.
The default consistency level of my collection is set to "Session". For my use-case I need a single authenticated web user to always have consistent data in terms of reads/writes between web requests.
I have some CosmosDB Repository logic that is made available to my controller logic via ASP.NET Core Singleton dependency injection as such:
services.AddSingleton<DocumentDBRepository, DocumentDBRepository>(x =>
new DocumentDBRepository(
WebUtil.GetMachineConfig("DOCDB_ENDPOINT", Configuration),
WebUtil.GetMachineConfig("DOCDB_KEY", Configuration),
WebUtil.GetMachineConfig("DOCDB_DB", Configuration),
"MyCollection",
maxDocDbCons));
DocumentDBRespository creates a cosmos client like so:
public DocumentDBRepository(string endpoint, string authkey, string database, string collection, int maxConnections)
{
_Collection = collection;
_DatabaseId = database;
_Client = new DocumentClient(new Uri(endpoint), authkey,
new ConnectionPolicy()
{
MaxConnectionLimit = maxConnections,
ConnectionMode = ConnectionMode.Direct,
ConnectionProtocol = Protocol.Tcp,
RetryOptions = new RetryOptions()
{
MaxRetryAttemptsOnThrottledRequests = 10
}
});
_Client.OpenAsync().Wait();
CreateDatabaseIfNotExistsAsync().Wait();
CreateCollectionIfNotExistsAsync().Wait();
}
As far as I understand that means one CosmosDB client per Web App server. I do have multiple web app servers, so a single user might hit the CosmosDB from multiple AppServers and different CosmosDb clients.
Before a user interacts with the ComosDB, I check their session object for a CosmosDb SessionToken, like so:
string docDbSessionToken = HttpContext.Session.GetString("StorageSessionToken");
Then, when writing a document for example, the method looks something like so:
public async Task<Document> CreateItemAsync<T>(T item, Ref<string> sessionTokenOut, string sessionTokenIn = null)
{
ResourceResponse<Document> response = null;
if (string.IsNullOrEmpty(sessionTokenIn))
{
response = await _Client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(_DatabaseId, _Collection), item);
}
else
{
response = await _Client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(_DatabaseId, _Collection), item, new RequestOptions() { SessionToken = sessionTokenIn });
}
sessionTokenOut.Value = response.SessionToken;
Document created = response.Resource;
return created;
}
The idea being that if we have a session token, we pass one in and use it. If we don't have one, just create the document and then return the newly created session token back to the caller. This works fine...
Except, I'm unclear as to why when I do pass in a session token, I get a DIFFERENT session token back. In other words, when _Client.CreateDocumentAsync returns, response.SessionToken is always different from parameter sessionTokenIn.
Does that mean I should be using the new session token from that point on for that user? Does it mean I should ignore the new session token and use the initial session token?
How long do one of these "sessions" even last? Are they sessions in the traditional sense?
Ultimately, I just need to make sure that the same user can always read their writes, regardless of which AppServer they connect with or how many other users are currently using the DB.
I guess the confusion here is on what a session is?
In most scenarios/frameworks treat session as static identifier (correlation), where as with cosmos the sessionToken is dynamic (kind of bookmark/representation of cosmos db state, which changes with writes). Naming it as 'sessionToken' might be root of the confusion.
In this specific scenario, you should use the "returned sessiontoken" from cosmos API's.

Twillio , connect between 2 numbers

I am trying to achieve following functionality with twillio.js on client side and ASP.NET Mvc website at the backend.
I need to connect a call between real phone number of sales person and phone number of a potential client.
For example on button click , I need to call potential client , and in a case the client answered , i need to add to the call sales person (that is not using twillio number , using regular landline)
Is it possible to achieve with twillio ?
Karen, hello!
Were you able to achieve what you were looking for with Alex's suggestion of the Click to Call tutorial?
https://www.twilio.com/docs/tutorials/walkthrough/click-to-call/csharp/mvc
The above uses a web form and ajax to send the form asynchronously. Then we handle the POST from our web form and connect the call via the REST API.
/// <summary>
/// Handle a POST from our web form and connect a call via REST API
/// </summary>
[HttpPost]
public ActionResult Call(Contact contact)
{
if (!ModelState.IsValid)
{
return Json(new { success = false, message = (ModelState.Values.First()).Errors.First().ErrorMessage, });
}
var twilioNumber = ConfigurationManager.AppSettings["TwilioNumber"];
// The following line is how you should get the absolute Uri in an internet faced
// server or a production environment
// var handlerUri = Url.Action("Connect", "Call", null, Request.Url.Scheme);
// this line allow us to get the absolute Uri in a local computer using a secure instrospectable
// service like ngrok ;)
var handlerUri = GetTestUri();
_twilioService.CallToNumber(twilioNumber, contact.Phone.Replace(" ", ""), handlerUri);
return Json(new { success = true, message = "Phone call incoming!"});
}
Please let me know if this is helpful for your use case.

ServiceStack: Can we Pass Data through a RequestFilterAttribute to the calling service

Maybe I'm thinking about this wrong, but I'm trying to create a custom attribute for our CMS to handle auth checks.
https://gist.github.com/sitefinitysteve/62ab761256a64a84d8a6#file-sitefinityjwt-cs-L39
So if this service is called from within the CMS from a logged in user, user data is all there for the service method already.
But in the context of being called from an app, the user is technically Anonymous, however I can decode the token and get the user just fine... but not sure how to like pass that over to the service.
Am I just maybe looking at this wrong, and the proper thing to do is to call a CMS API method to just log that person in (seems slow if I already have the persons user object from line 33, and the service context expires instantly.
Use Request.Items Dictionary
You would use the IRequest.Items dictionary for any data you want to pass throughout ServiceStack's Request Pipeline:
//RequestFilter:
req.Items["info"] = new MyRequestInfo { ... };
In Service:
var info = (MyRequestInfo)base.Request.Items["info"];
Have DTO's share common interface
Another option for adding extra info to your Service is to have Request DTO's implement an interfaces, e.g:
public interface IHasInfo
{
MyRequestInfo Info { get; set; }
}
Which you could then populate in your Request Filter, e.g:
((MyRequestInfo)dto).Info = new MyRequestInfo { ... };
Access in Service like any other DTO property, e.g:
public object Any(Request request)
{
var info = request.Info;
}

Restlet creation doesn't return ID

I'm currently PoCing a solution for OData interaction from Java. We have an WCF odata repository available. I began preliminary coding using the restlet API because it has code generation available but since using it I've encountered the situation where a newly created object doesn't have it's ID set upon creation and the addEntity method in the generated service class doesn't appear to return the ID?
Which is a more comprehensive solution, that from Restlet or OData4j?
Thanks,
Mark.
you can manually return the id where you are implementing the producer register method
for example:
producer.register(yourModelClass.class, "yourModelClass", new Func1<Object,Iterable<yourModelClass>>() {
public Iterable<yourModelClass> apply(Object queryInfo) {
return null;
}
}
}, "yourID");

paypal PPAPIService new SDK

Concerning the new Paypal SDK, there is almost no useful example code, and the Internet is littered with examples of the old SDK. My question concerns making an API request for a third party paypal account for which i have obtained the token and secretToken through the permissions API.
In attempting to construct a PPAPIService object, where is the list of possible sevice names?
ie: $this->serviceName = $serviceName; (in the constructor) What is the string syntax for these?
In regards to the makeRequest method, how do I define the $apiMethod variable, and what is the format of the $params variable? What are the different parameters?
A simple example of how to just obtain the account balance of the authorized third party account would be extremely helpful.
I am using PHP.
from the PPAPIService.php file:
class PPAPIService
{
public $endpoint;
public $serviceName;
private $logger;
public function __construct($serviceName = "")
{
$this->serviceName = $serviceName; //is there ANY documentation about the syntax and types of service names?
$config = PPConfigManager::getInstance();
$this->endpoint = $config->get('service.EndPoint');
$this->logger = new PPLoggingManager(__CLASS__);
}
public function setServiceName($serviceName)
{
$this->serviceName = $serviceName;
}
public function makeRequest($apiMethod, $params, $apiUsername = null, $accessToken = null, $tokenSecret = null)
{
//what are the apiMethod types? syntax? and params? type.. options...??
}
}
Well, you do not have to create a PPAPIService object directly. Let's say you want to use the Invoicing SDK, here's what you would do
$invoiceService = new InvoiceService();
$invoiceService->setAccessToken($accessToken);
$invoiceService->setTokenSecret($tokenSecret);
$createInvoiceResponse = $invoiceService->CreateInvoice($createInvoiceRequest);
There's one service class (such as InvoiceService in this code snippet) per API that you would instantiate as per your needs. The API username/password are picked from the configuration file and the access token/token secret are set via code since they typically tend to be different for different invocations.
Which API are you trying to call, by the way?
To answer on your other concern, the new PayPal SDK's have all the required samples bundled within the SDK itself. The SDK + Samples canbe downloaded from
https://www.x.com/developers/paypal/documentation-tools/paypal-sdk-index