{"id":3975,"date":"2023-03-22T12:13:16","date_gmt":"2023-03-22T12:13:16","guid":{"rendered":"https:\/\/info.documotor.com\/?page_id=3975"},"modified":"2023-03-22T12:13:16","modified_gmt":"2023-03-22T12:13:16","slug":"get_rest_api","status":"publish","type":"page","link":"https:\/\/info.documotor.com\/?page_id=3975","title":{"rendered":"Get_rest_api"},"content":{"rendered":"\n<p>Use this function to recieve data from an external API. <\/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 get_rest_api(string $baseUri, json_object $uriParameters, boolean $throwOnError)<\/code><\/pre>\n\n\n\n<h3>Parameters<\/h3>\n\n\n\n<p><strong>$baseUri:<\/strong> The URI (Uniform Resource Identifier) for the API&#8217;s GET request. Parameters are usually defined like <code>?=parameter<\/code> but in this function, it is defined: <code>?={parameterKey}<\/code> like in <a rel=\"noreferrer noopener\" href=\"https:\/\/info.documotor.com\/?page_id=3682\" data-type=\"URL\" data-id=\"https:\/\/info.documotor.com\/?page_id=3682\" target=\"_blank\">string_interpolate<\/a> where <code>parameter key<\/code> is defined in the $uriParameters JSON object.<\/p>\n\n\n\n<p><strong>$uriParameters: <\/strong>The parameters that should be inserted in the GET request $baseUri are defined as a JSON object. This object would be defined like <code>{ \"parameterKey\": \"parameter\"}<\/code>.<\/p>\n\n\n\n<p><strong>$throwOnError:<\/strong> A true or false value (boolean) that determines, in case of an error, whether the error response should be shown in the transformation result or if it should return <code>null<\/code>.<\/p>\n\n\n\n<h3>Example<\/h3>\n\n\n\n<pre title=\"Data\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n    \"employeeNo\": 123456\n}<\/code><\/pre>\n\n\n\n<pre title=\"Transformation\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">{\n    apiResult: get_rest_api(\"https:\/\/exampleservice.com\/api\/get-employee?id={userId}\", {\"userId\": employeeNo},`true`)\n}<\/code><\/pre>\n\n\n\n<pre title=\"Output\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n    \"apiResult\": {\n        \"name\": \"Hans Hansen\",\n        \"phone\": 87654321,\n        \"email\": \"hans@hansen.dk\"\n    }\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Use this function to recieve data from an external API. Syntax Parameters $baseUri: The URI (Uniform Resource Identifier) for the API&#8217;s GET request. Parameters are usually defined like ?=parameter but in this function, it is defined: ?={parameterKey} like in string_interpolate where parameter key is defined in the $uriParameters JSON object. $uriParameters: The parameters that should [&hellip;]<\/p>\n","protected":false},"author":12,"featured_media":0,"parent":271,"menu_order":61,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3975"}],"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=3975"}],"version-history":[{"count":15,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3975\/revisions"}],"predecessor-version":[{"id":5349,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3975\/revisions\/5349"}],"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=3975"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}