{"id":11937,"date":"2022-02-23T17:32:49","date_gmt":"2022-02-23T17:32:49","guid":{"rendered":"https:\/\/www.directimpactsolutions.com\/?p=11937"},"modified":"2024-01-02T16:11:44","modified_gmt":"2024-01-02T16:11:44","slug":"basic-authentication-in-api-integration","status":"publish","type":"post","link":"https:\/\/www.directimpactsolutions.com\/en\/basic-authentication-in-api-integration\/","title":{"rendered":"Basic Authentication in API Integration"},"content":{"rendered":"<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"570\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/API-Integration-1024x570.jpg\" alt=\"basic authentication in API integraiton\" class=\"wp-image-11958\" style=\"width:612px;height:341px\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/API-Integration-1024x570.jpg 1024w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/API-Integration-300x167.jpg 300w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/API-Integration-768x428.jpg 768w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/API-Integration-600x334.jpg 600w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/API-Integration.jpg 1500w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><p>Of all the FileMaker features introduced in the past five years, many feel that being able to specify cURL options for the Insert from URL script step is the most impactful. Why might that be?<\/p><p>With this feature, all third-party web services with APIs can be extensions of our FileMaker solutions, which expands what our FileMaker solutions can do. Developers can confidently take on web integration requests, and deliver them across the entire product line, including WebDirect and FileMaker Go.<\/p><p>Integration projects usually start with authentication. This article will explain how to approach basic authentication for a web integration.<\/p><h3 class=\"wp-block-heading\">Identify the endpoint URL for our requests<\/h3><p>When integrating with a web service, the first thing you must do is authenticate. The simplest scheme of authentication is called Basic Authentication. Basic Authentication asks you to provide a username and password to verify your identity and gain access.<\/p><p>Basic Authentication is quite common. In fact, FileMaker\u2019s Admin API on FileMaker Server uses this method. In this post, we\u2019ll use FileMaker\u2019s Admin API to construct an HTTP call for basic authentication.<\/p><p>First, we need to know where to send our request. The target of our request is called an endpoint URL.<\/p><h3 class=\"wp-block-heading\">FileMaker Admin API Documentation<\/h3><p>The easiest way to find that out is by reading the API documentation. API documentation can be intimidating to read, so we\u2019ll use the FileMaker Admin API documentation in this example. We\u2019ll point out the key information and how to interpret it.<\/p><p>The FileMaker Admin API documentation is installed when you install FileMaker Server. To access it, you can type the following URL in your web browser. Be sure to replace the host with your own host address. If you are on the host machine, you can use \u201clocalhost\u201d as the host address.<\/p><pre class=\"wp-block-code\"><code>https:&#47;&#47;&lt;host&gt;\/fmi\/admin\/apidoc\/<\/code><\/pre><p>The picture below shows what the FileMaker Admin API documentation looks like for the authentication method. On the very first line, it shows me the path (\/user\/auth) to access the authentication method.<\/p><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"618\" height=\"469\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/FileMaker-Admin-API-Authentication-Method-Documentation.png\" alt=\"\" class=\"wp-image-11938\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/FileMaker-Admin-API-Authentication-Method-Documentation.png 618w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/FileMaker-Admin-API-Authentication-Method-Documentation-300x228.png 300w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/FileMaker-Admin-API-Authentication-Method-Documentation-600x455.png 600w\" sizes=\"auto, (max-width: 618px) 100vw, 618px\" \/><\/figure><p>Admin API documentation for authentication<\/p><p>An endpoint URL is usually made of two parts: a root endpoint and a path. The root endpoint is usually described very early in the API documentation. Look for pages titled \u201cGetting started,\u201d or \u201cThe Basics,\u201d or \u201cOverview.\u201d For some APIs, your root endpoint might be unique to your user account. In those cases, you can typically find your root endpoint under your user\/account setting.<\/p><p>For the FileMaker Admin API, the root endpoint is:<\/p><pre class=\"wp-block-code\"><code>https:&#47;&#47;&lt;host&gt;\/fmi\/admin\/api\/&lt;version&gt;<\/code><\/pre><p>When we concatenate the root above with the path (\/user\/auth) we found, we get the full endpoint URL that our request should be sent to:<\/p><pre class=\"wp-block-code\"><code>https:&#47;&#47;&lt;host&gt;\/fmi\/admin\/api\/v2\/user\/auth<\/code><\/pre><p>Other API documentation typically provides path information in a similar format, especially if it\u2019s a REST API.<\/p><h3 class=\"wp-block-heading\">Mailchimp API Documentation<\/h3><p>Here\u2019s an example from Mailchimp\u2019s API documentation. After the method, it shows the path (\/authorized-apps). If we are integrating with the Mailchimp API and want to call this method, we\u2019d need to find our endpoint root for Mailchimp, then append the path to get the full endpoint URL.<\/p><figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1005\" height=\"131\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Mailchimp-API-Integration.png\" alt=\"\" class=\"wp-image-11940\" style=\"width:808px;height:105px\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Mailchimp-API-Integration.png 1005w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Mailchimp-API-Integration-300x39.png 300w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Mailchimp-API-Integration-768x100.png 768w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Mailchimp-API-Integration-600x78.png 600w\" sizes=\"auto, (max-width: 1005px) 100vw, 1005px\" \/><\/figure><h3 class=\"wp-block-heading\" style=\"padding-top:var(--wp--preset--spacing--40)\">Specify the cURL options<\/h3><p>Now that I know where my request should go, let\u2019s work on the cURL option. cURL options are information provided to the receiver of our request to help with the interpretation and processing of the request. This is like what we would write on an envelope to help a letter get delivered.<\/p><p>cURL is a big subject. This article won\u2019t cover full details about it. My goal is to provide a basic understanding and something you can copy and paste into your own solution. I\u2019ll write more about cURL options in separate articles.<\/p><p>Here\u2019s the sample code to put into the cURL option in your \u201cInsert from URL\u201d script step:<\/p><pre class=\"wp-block-preformatted\">\"--request POST\" &amp; \n\" --header \\\"content-type: application\/json\\\"\" &amp; \n\" --data @$requestBody \" &amp; $endpointURL &amp; \n\" --user \" &amp; Quote ( $username &amp; \":\" &amp; $password ) \n\/\/&amp; \" --header \\\"Authorization: Basic \" &amp; Base64EncodeRFC ( 4846 ; $username &amp; \":\" &amp; $username )  &amp; \"\\\"\"<\/pre><h3 class=\"wp-block-heading\">Basic Authentication<\/h3><p>For Basic Authentication, we need to specify 4 parameters:<\/p><ul class=\"wp-block-list\"><li>The first parameter (\u2013request) will tell the web service what kind of request we are making. In my case, the documentation tells me it is a POST request (see below).<\/li><\/ul><figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"654\" height=\"62\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Basic-Authentication-1.jpg\" alt=\"\" class=\"wp-image-11944\" style=\"width:657px;height:62px\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Basic-Authentication-1.jpg 654w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Basic-Authentication-1-300x28.jpg 300w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Basic-Authentication-1-600x57.jpg 600w\" sizes=\"auto, (max-width: 654px) 100vw, 654px\" \/><\/figure><ul class=\"wp-block-list\"><li> The second parameter (\u2013header) is very versatile. Here we use it to tell the web service what type of content it should receive. In my case, the documentation tells me the content type is application\/JSON (see below).<\/li><\/ul><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"656\" height=\"76\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Basic-Authentication-2.jpg\" alt=\"\" class=\"wp-image-11946\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Basic-Authentication-2.jpg 656w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Basic-Authentication-2-300x35.jpg 300w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Basic-Authentication-2-600x70.jpg 600w\" sizes=\"auto, (max-width: 656px) 100vw, 656px\" \/><\/figure><ul class=\"wp-block-list\"><li>The third parameter (\u2013data) will specify where to find the data carried by request. The data we are sending here is also referred to as the payload of the request.<\/li><\/ul><p style=\"padding-left:var(--wp--preset--spacing--60)\">You might notice that my variable $requestBody is within quotes. This is intentional. We are specifying the&nbsp;<strong>location<\/strong>&nbsp;of the data, not the data itself. In this example, the data is in a variable. I\u2019m telling the script step the name of the variable.<\/p><p style=\"padding-left:var(--wp--preset--spacing--60)\">In other cases, the data might be stored in a file. In that case, you would need to specify the file path after the \u201c@\u201d sign.<\/p><ul class=\"wp-block-list\"><li>4. The last parameter and the most important one for this request (\u2013user), will specify the username and password for basic authentication.<\/li><\/ul><p style=\"padding-left:var(--wp--preset--spacing--60)\">You can also use the \u2013header parameter to specify the username and password, as shown in the 5th line of the sample code. This is a more generic syntax that can be used with authentication schemes other than basic authentication.<\/p><p style=\"padding-left:var(--wp--preset--spacing--60)\">In this example, you can see that the \u2013header option has more complicated syntax, so we\u2019ll use the \u2013user option. By adding error trapping, our script will look like this:<\/p><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"83\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Basic-Authentication.jpg\" alt=\"\" class=\"wp-image-11950\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Basic-Authentication.jpg 1024w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Basic-Authentication-300x24.jpg 300w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Basic-Authentication-768x62.jpg 768w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Basic-Authentication-600x49.jpg 600w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><h3 class=\"wp-block-heading\" style=\"padding-top:var(--wp--preset--spacing--30)\">Processing the Result<\/h3><p>According to the documentation (shown below), we should get a response in JSON format that contains an authentication token:<\/p><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"583\" height=\"290\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Response-when-successful.png\" alt=\"\" class=\"wp-image-11952\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Response-when-successful.png 583w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Response-when-successful-300x149.png 300w\" sizes=\"auto, (max-width: 583px) 100vw, 583px\" \/><\/figure><p>Successful call response<\/p><p>Let\u2019s think about the integration like going to a museum. The basic authentication is like showing our ID and tickets to get in. After this, we get a wristband so we don\u2019t have to show ID and tickets every time we want to come back on the same day. In this example, the token from the JSON response is the wristband.<\/p><p>To parse out the token, we can use the JSONGetElement function.<\/p><p>If we pass it to the wrong credential, we get an error in the JSON format:<\/p><figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"581\" height=\"244\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Failed-Call-Response.png\" alt=\"\" class=\"wp-image-11954\" style=\"width:584px;height:245px\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Failed-Call-Response.png 581w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Failed-Call-Response-300x126.png 300w\" sizes=\"auto, (max-width: 581px) 100vw, 581px\" \/><\/figure><p>Failed call response<\/p><p>In this case, the response returns an error code and descriptive text. We can parse them out using the JSONGetElement function, then handle the error according to our error handling logic.<\/p><p>You\u2019ll find response samples in other API documentation. Here\u2019s an example from the Mailchimp API:<\/p><figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"985\" height=\"1024\" src=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Mailchimp-API-Response-Sample.png\" alt=\"\" class=\"wp-image-11956\" style=\"width:591px;height:615px\" srcset=\"https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Mailchimp-API-Response-Sample.png 985w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Mailchimp-API-Response-Sample-289x300.png 289w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Mailchimp-API-Response-Sample-768x798.png 768w, https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/Mailchimp-API-Response-Sample-600x624.png 600w\" sizes=\"auto, (max-width: 985px) 100vw, 985px\" \/><\/figure><p>Mailchimp API Response Sample<\/p><p>Prefer to learn in video format? We\u2019ve covered this topic on our YouTube channel&nbsp;<a href=\"https:\/\/youtu.be\/ynskty511LY\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>. Happy developing!<\/p><p>If you have questions about the content in this article, feel free to <a href=\"http:\/\/directimpactsolutions.com\/en\/contact-us\/\">contact us<\/a>!<\/p><hr class=\"wp-block-separator has-alpha-channel-opacity\" style=\"margin-top:var(--wp--preset--spacing--70);margin-bottom:var(--wp--preset--spacing--70)\"\/><p class=\"has-small-font-size\"><em>*This article was originally written for AppWorks, which has since joined Direct Impact Solutions. This article is intended for informative purposes only. To the best of our knowledge, this information is accurate as of the date of publication.<\/em><\/p>","protected":false},"excerpt":{"rendered":"<p>Of all the FileMaker features introduced in the past five years, many feel that being able to specify cURL options for the Insert from URL script step is the most impactful. Why might that be? With this feature, all third-party web services with APIs can be extensions of our FileMaker solutions, which expands what our &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/www.directimpactsolutions.com\/en\/basic-authentication-in-api-integration\/\"> <span class=\"screen-reader-text\">Basic Authentication in API Integration<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":11,"featured_media":11958,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","footnotes":""},"categories":[29],"tags":[228,39,229],"class_list":["post-11937","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-low-code","tag-api","tag-filemaker","tag-integration"],"uagb_featured_image_src":{"full":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/API-Integration.jpg",1500,835,false],"thumbnail":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/API-Integration-150x150.jpg",150,150,true],"medium":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/API-Integration-300x167.jpg",300,167,true],"medium_large":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/API-Integration-768x428.jpg",768,428,true],"large":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/API-Integration-1024x570.jpg",1024,570,true],"1536x1536":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/API-Integration.jpg",1500,835,false],"2048x2048":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/API-Integration.jpg",1500,835,false],"woocommerce_thumbnail":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/API-Integration-300x300.jpg",300,300,true],"woocommerce_single":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/API-Integration-600x334.jpg",600,334,true],"woocommerce_gallery_thumbnail":["https:\/\/www.directimpactsolutions.com\/wp-content\/uploads\/2023\/05\/API-Integration-100x100.jpg",100,100,true]},"uagb_author_info":{"display_name":"Weihao Ding","author_link":"https:\/\/www.directimpactsolutions.com\/en\/author\/weihao-dingdirectimpactsolutions-com\/"},"uagb_comment_info":1,"uagb_excerpt":"Of all the FileMaker features introduced in the past five years, many feel that being able to specify cURL options for the Insert from URL script step is the most impactful. Why might that be? With this feature, all third-party web services with APIs can be extensions of our FileMaker solutions, which expands what our&hellip;","_links":{"self":[{"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/posts\/11937","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/comments?post=11937"}],"version-history":[{"count":4,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/posts\/11937\/revisions"}],"predecessor-version":[{"id":16341,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/posts\/11937\/revisions\/16341"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/media\/11958"}],"wp:attachment":[{"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/media?parent=11937"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/categories?post=11937"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.directimpactsolutions.com\/en\/wp-json\/wp\/v2\/tags?post=11937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}