{"id":12,"date":"2019-10-01T14:26:26","date_gmt":"2019-10-01T14:26:26","guid":{"rendered":"https:\/\/docs_v3.dataforseo.com\/?page_id=12"},"modified":"2021-03-19T15:11:20","modified_gmt":"2021-03-19T15:11:20","slug":"auth","status":"publish","type":"page","link":"https:\/\/docs.dataforapps.com\/v3\/auth\/","title":{"rendered":"Authentication"},"content":{"rendered":"<p>[vc_row][vc_column][vc_column_text]<\/p>\n<h1>Authentication<\/h1>\n<p>[\/vc_column_text]\n        <blockquote>\n            <p>To authorize, use this code:<\/p>\n        <\/blockquote>\n        <pre class=\"highlight php tab-php\" style=\"display: block;\"><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\" data-enlighter-theme=\"mocha\">&lt;?php\r\nrequire('RestClient.php');\r\n\/\/You can download this file from here https:\/\/cdn.dataforapps.com\/v3\/examples\/php\/php_RestClient.zip\r\n\r\ntry {\r\n    \/\/Instead of 'login' and 'password' use your credentials from https:\/\/app.dataforapps.com\/api-dashboard\r\n    $client = new RestClient('https:\/\/api.dataforapps.com\/', null, 'login', 'password');\r\n\r\n    \/\/do something\r\n\r\n} catch (RestClientException $e) {\r\n    echo \"\\n\";\r\n    print \"HTTP code: {$e-&gt;getHttpCode()}\\n\";\r\n    print \"Error code: {$e-&gt;getCode()}\\n\";\r\n    print \"Message: {$e-&gt;getMessage()}\\n\";\r\n    print  $e-&gt;getTraceAsString();\r\n    echo \"\\n\";\r\n    exit();\r\n}\r\n?&gt;<\/pre>\n<p><\/pre>\n        <pre class=\"highlight python tab-python\" style=\"display: none;\">\n            <\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"mocha\">from client import RestClient\r\n#You can download this file from here https:\/\/cdn.dataforapps.com\/v3\/examples\/python\/python_Client.zip\r\n\r\n#Instead of 'login' and 'password' use your credentials from https:\/\/app.dataforapps.com\/api-dashboard\r\nclient = RestClient(\"login\", \"password\")\r\n\r\n#do something<\/pre>\n<p>\n        <\/pre>\n        <pre class=\"highlight csharp tab-csharp\" style=\"display: none;\">\n            <\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"mocha\">using System;\r\nusing System.Net.Http;\r\nusing System.Net.Http.Headers;\r\nusing System.Text;\r\nusing System.Threading.Tasks;\r\nusing Newtonsoft.Json;\r\n\r\nnamespace DataForSeoDemos\r\n{\r\n    public static partial class Demos\r\n    {\r\n        public static async Task cmn_key_id()\r\n        {\r\n            var httpClient = new HttpClient\r\n            {\r\n                BaseAddress = new Uri(\"https:\/\/api.dataforapps.com\/\"),\r\n\r\n                \/\/Instead of 'login' and 'password' use your credentials from https:\/\/app.dataforapps.com\/api-dashboard\r\n                DefaultRequestHeaders = { Authorization = new AuthenticationHeaderValue(\"Basic\", Convert.ToBase64String(Encoding.ASCII.GetBytes(\"login:password\"))) }\r\n            };\r\n\r\n            \/\/ do something\r\n        }\r\n    }\r\n}<\/pre>\n<p>\n        <\/pre>\n        <blockquote>\n            <p>Instead of \u2018login\u2019 and \u2018password\u2019 use your credentials from https:\/\/app.dataforapps.com\/api-dashboard<\/p>\n        <\/blockquote>[vc_column_text]<a href=\"https:\/\/app.dataforapps.com\/register\" target=\"_blank\" rel=\"noopener noreferrer\">Create an account<\/a> with DataForApps and then use the credentials from your account <a href=\"https:\/\/app.dataforapps.com\/api-dashboard\" target=\"_blank\" rel=\"noopener noreferrer\">dashboard<\/a> to access DataForApps APIs. Note that the API password is generated automatically by DataForApps and is different from your account password.<\/p>\n<p>DataForApps is using the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Basic_access_authentication\">Basic Authentication<\/a>, which makes it possible to call our APIs with almost any programming language, Postman app, REST API platforms, and all major frameworks.<\/p>\n<p>Regardless of the programming language, your unique API token should be passed <strong>in the &#8216;Authorization&#8217; header<\/strong> within the request in the following format:<br \/>\n<code>Authorization: Basic login:password<\/code><\/p>\n<p>Instead of &#8220;login&#8221; and &#8220;password&#8221;, use your API credentials encoded in Base64.<br \/>\nFor instance, the Base64-encoded &#8216;login:password&#8217; value will have the following format:<br \/>\n<code>bG9naW46cGFzc3dvcmQ=<\/code><\/p>\n<p>So the whole string will look as follows:<br \/>\n<code>Authorization: Basic bG9naW46cGFzc3dvcmQ=<\/code><\/p>\n<p>Check the examples for PHP, Python, and C# on the right to see how it works with a particular programming language.<\/p>\n<p>Note that it is not possible to pass the login and password in URL parameters. Also, you do not have to make a separate authentication call to obtain API credentials. Basic authentication is the only way to access DataForApps API; credentials should always be passed in the header of the request.<\/p>\n<p>[\/vc_column_text][\/vc_column][\/vc_row]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[vc_row][vc_column][vc_column_text] Authentication [\/vc_column_text][vc_column_text]Create an account with DataForApps and then use the credentials from your account dashboard to access DataForApps APIs. Note that the API password is generated automatically by DataForApps and is different from your account password. DataForApps is using the Basic Authentication, which makes it possible to call our APIs with almost any programming [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"template.php","meta":{"footnotes":""},"_links":{"self":[{"href":"https:\/\/docs.dataforapps.com\/v3\/wp-json\/wp\/v2\/pages\/12"}],"collection":[{"href":"https:\/\/docs.dataforapps.com\/v3\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/docs.dataforapps.com\/v3\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/docs.dataforapps.com\/v3\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.dataforapps.com\/v3\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":67,"href":"https:\/\/docs.dataforapps.com\/v3\/wp-json\/wp\/v2\/pages\/12\/revisions"}],"predecessor-version":[{"id":8690,"href":"https:\/\/docs.dataforapps.com\/v3\/wp-json\/wp\/v2\/pages\/12\/revisions\/8690"}],"wp:attachment":[{"href":"https:\/\/docs.dataforapps.com\/v3\/wp-json\/wp\/v2\/media?parent=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}