{"id":3987,"date":"2023-03-22T11:54:35","date_gmt":"2023-03-22T11:54:35","guid":{"rendered":"https:\/\/info.documotor.com\/?page_id=3987"},"modified":"2023-03-22T11:58:11","modified_gmt":"2023-03-22T11:58:11","slug":"service","status":"publish","type":"page","link":"https:\/\/info.documotor.com\/?page_id=3987","title":{"rendered":"Service"},"content":{"rendered":"\n<p>Fetches data from an external service by calling a connected service\u2018s operation and a payload if needed.  <\/p>\n\n\n\n<h3>Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">json_object service(string $service, string $operation, any $payload)<\/code><\/pre>\n\n\n\n<h3>Parameters<\/h3>\n\n\n\n<p><strong>$service:<\/strong> The name of the connected service in the unit. Read more about connected services and how to create one <a rel=\"noreferrer noopener\" href=\"https:\/\/info.documotor.com\/?page_id=2169\" data-type=\"URL\" data-id=\"https:\/\/info.documotor.com\/?page_id=2169\" target=\"_blank\">here<\/a>.<br><strong>$operation: <\/strong>The name of the operation in the <a rel=\"noreferrer noopener\" href=\"https:\/\/info.documotor.com\/?page_id=2169#operations\" data-type=\"URL\" data-id=\"https:\/\/info.documotor.com\/?page_id=2169#operations\" target=\"_blank\">service<\/a>. <br><strong>$payload:<\/strong> Information in the data that can be forwarded with the request in order to specify the request.  For operations utilizing GET, the payload must be a flat key\/value object.<\/p>\n\n\n\n<h3>Example<\/h3>\n\n\n\n<p>In the connected service following information is listed:<br><em>Name:<\/em> Forecast (manually typed)<br><em>Operation: <\/em>Weather (manually typed)<br><em>Type:<\/em> <code>GET<\/code> or <code>POST<\/code><br><em>URL:<\/em> The URL to the service, in this case: <code>https:\/\/api.open-forecast_example.com\/v1\/forecast?<\/code><br><em>Response Type:<\/em> <code>Unspecified <\/code>format or <code>JSON <\/code>format<br><\/p>\n\n\n\n<div class=\"wp-block-image is-style-default\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" width=\"720\" height=\"348\" src=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2022\/12\/image.png\" alt=\"\" class=\"wp-image-4082\" srcset=\"https:\/\/info.documotor.com\/wp-content\/uploads\/2022\/12\/image.png 720w, https:\/\/info.documotor.com\/wp-content\/uploads\/2022\/12\/image-300x145.png 300w\" sizes=\"(max-width: 720px) 100vw, 720px\" \/><\/figure><\/div>\n\n\n\n<pre title=\"Data\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n   \/\/Nothing is needed here when a connected service is used  \n}<\/code><\/pre>\n\n\n\n<pre title=\"Transformation\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">{\n    Forecast: service('Forecast', 'Weather', \n    {\n        latitude: '55.628648', \n        longitude: '12.589531', \n    })\n}<\/code><\/pre>\n\n\n\n<pre title=\"Output\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n    \"Forecast\": {\n        \"temperatureCelcius\": 22.5,\n        \"temperatureFahrenheit\": 72.5,\n        \"type\": \"Sunny\"\n    }\n}<\/code><\/pre>\n\n\n\n<p>From the documentation of the &#8220;Weather&#8221; API, we know we can find information about latitude and longitude if we forward keys with some specific numbers as values. To get this information, a flat key\/value object is forwarded with the GET request as payload, and using our connected service &#8216;Forecast&#8217; and the operation (endpoint) Weather, the information is returned from the API. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Fetches data from an external service by calling a connected service\u2018s operation and a payload if needed. Syntax Parameters $service: The name of the connected service in the unit. Read more about connected services and how to create one here.$operation: The name of the operation in the service. $payload: Information in the data that can [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":0,"parent":271,"menu_order":182,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3987"}],"collection":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3987"}],"version-history":[{"count":19,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3987\/revisions"}],"predecessor-version":[{"id":5342,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3987\/revisions\/5342"}],"up":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/271"}],"wp:attachment":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}