Is it support gRPC Request in business central14?

Hi Expert,

i want to call RPC APIs request in business central 14 via AL code.

could you please help me how to call?

Hi @bala_Gopu,

Have you resolved your doubt?

Two years ago I did an integration with a software that used RPC API, but in C/AL… convert C/AL to AL is a simple thing, but now I don’t have access to this project, perhaps tomorrow if you still need it.

Hi Pjllaneras,

thanks for the response, i did not get any solution.

No, not able to find the solution.

advance thanks

Hi @bala_Gopu,

This was a project to import invoices from Odoo ERP.

First, you need the endpoint. There is only 1 endpoint, and all request are made using a HttpPOST. In Oddo, first we need to do authentication, we need database name, user and password:

LOCAL GetAPIUserId(ConnectionCode : Code[20]) UserId : Integer
'JsonContentLbl: label {"jsonrpc": "2.0", "method": "call", "params": {"service": "common", "method": "login", "args": ["%1", "%2", "%3"]}}
IF EVALUATE(UserId, PMSConnection."API Id") AND (UserId <> 0) THEN
  EXIT;

Url := PMSConnection."Base URL" + 'jsonrpc';

Content := STRSUBSTNO(JsonContentLbl, PMSConnection."Database Name", PMSConnection."PMS Connection User", PMSConnection."PMS Connection Password");

Response := HttpPOST(Content,Url);

JsonObj := JsonObj.Parse(Content);
PMSConnection."API Id" := GetObjectValue(JsonObj, 'result');
IF PMSConnection."API Id" = '' THEN
  ERROR('Astrohotel: ' + CredentialsErr);

EVALUATE(UserId, PMSConnection."API Id");
PMSConnection.MODIFY;

To import invoices, in this case, we need to do 2 calls, one for all headers and one for lines, this is for get invoices header:

'JsonContentLbl: label {"jsonrpc": "2.0", "method": "call", "params": {"service": "object", "method": "execute", "args": ["%1", %2, "%3", "%4", "search_read", %5, %6]}}
ModelName := 'account.move';
IF Hotel <> '' THEN
  FilterString := STRSUBSTNO('[["company_id", "=", %1],["brand_id", "=", %2],["state", "=", "posted"],["type", "in", ["out_invoice","out_refund"]]]', Company, Hotel)
ELSE
  FilterString := STRSUBSTNO('[["company_id", "in", [%1]],["brand_id", "=", false],["state", "=", "posted"],["type", "in", ["out_invoice","out_refund"]]]', Param);
FieldsString :='["company_id", "brand_id", "type", "name", "date", "invoice_date", "invoice_date_due", "partner_id", "ref", "reservation_id", "invoice_origin", "currency_id", "amount_untaxed", ' +
        '"amount_tax", "amount_total", "amount_total_signed", "state", "invoice_payment_state", "payment_mode_id", "refund_invoice_ids"]';
Content := STRSUBSTNO(JsonContentLbl, PMSConnection."Database Name", GetAPIUserId(ConnectionCode), PMSConnection."PMS Connection Password", ModelName, FilterString, FieldsString);
Response := HttpPOST(Content ,Url);
// process response

Function POST:

LOCAL HttpPOST(Content: Text;Url : Text)Response: Text
'Name	DataType	Subtype	Length
'HttpResponseMessage	DotNet	System.Net.Http.HttpResponseMessage.'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'	
'HttpClient	DotNet	System.Net.Http.HttpClient.'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'	
'HttpContent	DotNet	System.Net.Http.HttpContent.'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'	
'StringContent	DotNet	System.Net.Http.StringContent.'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'	
'Encoding	DotNet	System.Text.Encoding.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'	
'ContentType	Text		
'Status	Integer
HttpClient := HttpClient.HttpClient();

ContentType := 'application/json';
HttpContent := StringContent.StringContent(Content,Encoding.UTF8,ContentType);
HttpResponseMessage := HttpResponseMessage.HttpResponseMessage;

HttpResponseMessage := HttpClient.PostAsync(Url,HttpContent).Result;
Status := HttpResponseMessage.StatusCode;
Response := HttpResponseMessage.Content.ReadAsStringAsync().Result;

IF NOT HttpResponseMessage.IsSuccessStatusCode THEN
  ERROR(ProcessMessage(HttpClient,HttpResponseMessage,ContentOrResponse));

After getting invoice headers we have to get invoice lines, but this is another history (tip: model name is “account.move.line”).

I hope this can help you.