{"id":38487,"date":"2022-01-27T11:20:26","date_gmt":"2022-01-27T11:20:26","guid":{"rendered":"https:\/\/arquiconsult.com\/?p=38487"},"modified":"2024-10-23T11:00:58","modified_gmt":"2024-10-23T10:00:58","slug":"odata-v4-unbound-actions","status":"publish","type":"post","link":"https:\/\/arquiconsult.com\/en\/odata-v4-unbound-actions\/","title":{"rendered":"#013 CODEUNIT API\u2019s \u2013 ODATA V4 UNBOUND ACTIONS"},"content":{"rendered":"<div class=\"services_vertical horizontal_services row\" style=\"background-color: #f7f7f7; padding: 25px; border-radius: 5px; text-align: justify;\">\n<p>One of the key recommendations to improve Web Services performance in Business Central is to use OData protocol instead of the deprecated and old-fashioned SOAP.<\/p>\n<p>According to Microsoft documentation<sup>A<\/sup>, using OData protocol in a Web Service can be up to 10 times faster than using the SOAP protocol.<\/p>\n<p>Publishing a Web Service using OData protocol is simple when an entity is provided (Page or Query). When a Codeunit is published as a Web Service, only the SOAP Url is automatically provided. However, it is possible to call a Codeunit published Web Service using OData protocol, turning it into an \u201cAPI Codeunit\u201d.<\/p>\n<\/div>\n<p><sup>(A) <\/sup><a href=\"https:\/\/docs.microsoft.com\/en-us\/dynamics365\/business-central\/dev-itpro\/performance\/performance-developer#writing-efficient-web-services\" target=\"_blank\" rel=\"noopener\">Writing efficient Web Services<\/a><\/p>\n<p style=\"font-weight: 400; text-align: left;\"><strong>Step 1: Create your Web Service Codeunit<\/strong><\/p>\n<p>In this example it is created a Codeunit with method that returns a<br \/>\nJson array containing Customer\u2019s data, according to a No. and Name filter:<\/p>\n<p><img loading=\"lazy\" class=\" wp-image-37807 aligncenter\" src=\"https:\/\/arquiconsult.com\/wp-content\/uploads\/2022\/01\/Step-1-Create-your-Web-Service-Codeunit-492x480.png\" alt=\"Step 1 Create your Web Service Codeunit\" width=\"562\" height=\"548\" srcset=\"https:\/\/arquiconsult.com\/wp-content\/uploads\/2022\/01\/Step-1-Create-your-Web-Service-Codeunit-492x480.png 492w, https:\/\/arquiconsult.com\/wp-content\/uploads\/2022\/01\/Step-1-Create-your-Web-Service-Codeunit-768x749.png 768w, https:\/\/arquiconsult.com\/wp-content\/uploads\/2022\/01\/Step-1-Create-your-Web-Service-Codeunit.png 830w\" sizes=\"(max-width: 562px) 100vw, 562px\" title=\"-\"><\/p>\n<p style=\"font-weight: 400; text-align: left;\"><strong>Step 2: Publish your app and publish your Codeunit as a Web Service<\/strong><\/p>\n<p>Go to the Web Services page and insert a new record with:<\/p>\n<p><strong>1. Object Type =<\/strong> Codeunit;<\/p>\n<p><strong>2. Object ID =<\/strong> Your Codeunit Id;<\/p>\n<p><strong>3. Service Name =<\/strong> Type the service name (example: CustWS);<\/p>\n<p><strong>4. Published =<\/strong> Yes.<\/p>\n<p><img loading=\"lazy\" class=\" wp-image-37810 aligncenter\" src=\"https:\/\/arquiconsult.com\/wp-content\/uploads\/2022\/01\/Step-2-Publish-your-app-and-publish-your-Codeunit-as-a-Web-Service-640x132.png\" alt=\"Step 2 Publish your app and publish your Codeunit as a Web Service\" width=\"718\" height=\"148\" srcset=\"https:\/\/arquiconsult.com\/wp-content\/uploads\/2022\/01\/Step-2-Publish-your-app-and-publish-your-Codeunit-as-a-Web-Service-640x132.png 640w, https:\/\/arquiconsult.com\/wp-content\/uploads\/2022\/01\/Step-2-Publish-your-app-and-publish-your-Codeunit-as-a-Web-Service-768x158.png 768w, https:\/\/arquiconsult.com\/wp-content\/uploads\/2022\/01\/Step-2-Publish-your-app-and-publish-your-Codeunit-as-a-Web-Service.png 963w\" sizes=\"(max-width: 718px) 100vw, 718px\" title=\"-\"><\/p>\n<p style=\"font-weight: 400; text-align: left;\"><strong>Step 3: Obtain the Url to call the Web Service<\/strong><\/p>\n<p>By definition, an OData base url in Business Central is composed as it follows:<\/p>\n<p><strong>http:\/\/&lt;ServerName&gt;:&lt;ODataPort&gt;\/&lt;ServerInstance&gt;\/ ODataV4\/<\/strong><\/p>\n<p>The url is then followed by the service name and the company parameter:<\/p>\n<p><strong>&lt;ServiceName&gt;?company=&lt;CompanyName&gt;<\/strong><\/p>\n<p>To call an unbound action, in addition to the Service Name, we need to add the method to call, so this is the standard url:<\/p>\n<p><strong>http:\/\/&lt;ServerName&gt;:&lt;ODataPort&gt;\/&lt;ServerInstance&gt;\/\u00a0ODataV4\/&lt;ServiceName_MethodName&gt;?company=&lt;CompanyName&gt;<\/strong><\/p>\n<p style=\"font-weight: 400; text-align: left;\"><strong>Example:<\/strong><\/p>\n<p>http:\/\/localhost:7163\/BC190\/ODataV4\/CustWS_GetCustomer?company=3adc449e-8621-ec11-bb76-000d3a2993<\/p>\n<p style=\"font-weight: 400; text-align: left;\"><strong>Step 4: T<\/strong><strong>est your Web Service<\/strong><\/p>\n<p>Using Postman, you can now test your Web Service<sup>2<\/sup>.<\/p>\n<p><img loading=\"lazy\" class=\"size-medium wp-image-37813 aligncenter\" src=\"https:\/\/arquiconsult.com\/wp-content\/uploads\/2022\/01\/Step-4-Test-your-Web-Service-640x345.png\" alt=\"Step 4 Test your Web Service\" width=\"640\" height=\"345\" srcset=\"https:\/\/arquiconsult.com\/wp-content\/uploads\/2022\/01\/Step-4-Test-your-Web-Service-640x345.png 640w, https:\/\/arquiconsult.com\/wp-content\/uploads\/2022\/01\/Step-4-Test-your-Web-Service-768x414.png 768w, https:\/\/arquiconsult.com\/wp-content\/uploads\/2022\/01\/Step-4-Test-your-Web-Service.png 930w\" sizes=\"(max-width: 640px) 100vw, 640px\" title=\"-\"><\/p>\n<!--themify_builder_content-->\n<div id=\"themify_builder_content-38487\" data-postid=\"38487\" class=\"themify_builder_content themify_builder_content-38487 themify_builder tf_clear\">\n    \t<!-- module_row -->\n\t<div  data-lazy=\"1\" class=\"module_row themify_builder_row tb_nus1581 tb_first tf_clearfix\">\n\t    \t\t<div class=\"row_inner col_align_top col-count-1 tf_box tf_w tf_rel\">\n\t\t\t<div  data-lazy=\"1\" class=\"module_column tb-column col-full first tb_cai8581 tf_box\">\n\t\t\t    \t        <div class=\"tb-column-inner tf_box tf_w\">\n\t\t    <!-- module text -->\n<div  class=\"module module-text tb_9tkr581 arquitps-data  \" data-lazy=\"1\">\n        <div  class=\"tb_text_wrap\">\n    <p><script>\njQuery(\".tbp_post_month:contains(Janeiro)\").html(\"January\");\n\njQuery(\".tbp_post_month:contains(Fevereiro)\").html(\"February\");\n\n\njQuery(\".tbp_post_month:contains(Mar\u00e7o)\").html(\"March\");\n\n\njQuery(\".tbp_post_month:contains(Abril)\").html(\"April\");\n\n\njQuery(\".tbp_post_month:contains(Maio)\").html(\"May\");\n\n\njQuery(\".tbp_post_month:contains(Junho)\").html(\"June\");\n\n\njQuery(\".tbp_post_month:contains(Julho)\").html(\"July\");\n\njQuery(\".tbp_post_month:contains(Agosto)\").html(\"August\");\n\njQuery(\".tbp_post_month:contains(Setembro)\").html(\"September\");\n\njQuery(\".tbp_post_month:contains(Outubro)\").html(\"October\");\n\njQuery(\".tbp_post_month:contains(Novembro)\").html(\"November\");\n\njQuery(\".tbp_post_month:contains(Dezembro)\").html(\"December\");\t\n\n\n\n<\/script><\/p>    <\/div>\n<\/div>\n<!-- \/module text -->\t        <\/div>\n\t    \t<\/div>\n\t\t    <\/div>\n\t    <!-- \/row_inner -->\n\t<\/div>\n\t<!-- \/module_row -->\n\t\t<!-- module_row -->\n\t<div  data-anchor=\"sucesso\" data-hide-anchor=\"1\" data-lazy=\"1\" class=\"module_row themify_builder_row sucesso repeat tb_has_section tb_section-sucesso tb_fywd81 tf_clearfix\" >\n\t    \t\t<div class=\"row_inner col_align_top col-count-1 tf_box tf_w tf_rel\">\n\t\t\t<div  data-lazy=\"1\" class=\"module_column tb-column col-full first tb_dq3782 tf_box\">\n\t\t\t    \t        <div class=\"tb-column-inner tf_box tf_w\">\n\t\t    <!-- module buttons -->\n<div  class=\"module module-buttons tb_jyd882 buttons-horizontal transparent popmake-24705 large circle tf_textc\" data-lazy=\"1\">\n    \t<div class=\"module-buttons-item tf_inline_b\">\n\t\t\t\t\t\t\t<a href=\"#\" class=\"ui builder_button tb_default_color\" >\n\t\t\t\t\t\t\t\t\t\t\t<span class=\"tf_inline_b tf_vmiddle\">Give as a Feedback and Suggest Questions<\/span>\n\t\t\t\t\t\t\t\t\t\t\t<\/a>\n\t\t\t    \t<\/div>\n\t<\/div>\n<!-- \/module buttons -->\n\t        <\/div>\n\t    \t<\/div>\n\t\t    <\/div>\n\t    <!-- \/row_inner -->\n\t<\/div>\n\t<!-- \/module_row -->\n\t<\/div>\n<!--\/themify_builder_content-->\n","protected":false},"excerpt":{"rendered":"<p>One of the key recommendations to improve Web Services performance in Business Central is to use OData protocol instead of the deprecated and old-fashioned SOAP. According to Microsoft documentationA, using OData protocol in a Web Service can be up to 10 times faster than using the SOAP protocol. Publishing a Web Service using OData protocol [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":37987,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2099],"tags":[2076,2079],"acf":[],"_links":{"self":[{"href":"https:\/\/arquiconsult.com\/en\/wp-json\/wp\/v2\/posts\/38487"}],"collection":[{"href":"https:\/\/arquiconsult.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arquiconsult.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arquiconsult.com\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/arquiconsult.com\/en\/wp-json\/wp\/v2\/comments?post=38487"}],"version-history":[{"count":0,"href":"https:\/\/arquiconsult.com\/en\/wp-json\/wp\/v2\/posts\/38487\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/arquiconsult.com\/en\/wp-json\/wp\/v2\/media\/37987"}],"wp:attachment":[{"href":"https:\/\/arquiconsult.com\/en\/wp-json\/wp\/v2\/media?parent=38487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arquiconsult.com\/en\/wp-json\/wp\/v2\/categories?post=38487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arquiconsult.com\/en\/wp-json\/wp\/v2\/tags?post=38487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}