Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
protogrid:json_api_authentication [2017-12-08 11:39] – 46.140.51.3 | protogrid:json_api_authentication [2017-12-08 17:37] – pgrid_wiki_admin | ||
---|---|---|---|
Line 6: | Line 6: | ||
A POST http request to the API endpoint “/ | A POST http request to the API endpoint “/ | ||
- | HTTP Header | + | HTTP header |
| < | | < | ||
| ::: |Either < | | ::: |Either < | ||
Line 18: | Line 18: | ||
https:// | https:// | ||
</ | </ | ||
- | Request | + | Request |
<code json> | <code json> | ||
{ | { | ||
- | POST / | + | |
- | Host: your_environment.protogrid.com | + | Host: your_environment.protogrid.com |
- | user_id: example_user | + | user_id: example_user |
- | user_secret: | + | user_secret: |
} | } | ||
</ | </ | ||
Line 32: | Line 32: | ||
<code jquery> | <code jquery> | ||
$.ajax({ | $.ajax({ | ||
- | | + | |
- | url: ' | + | url: ' |
- | contentType: | + | contentType: |
- | dataType: ' | + | dataType: ' |
- | beforeSend: function(xhr){ | + | beforeSend: function(xhr){ |
- | xhr.setRequestHeader(' | + | xhr.setRequestHeader(' |
- | xhr.setRequestHeader(' | + | xhr.setRequestHeader(' |
- | } | + | } |
}); | }); | ||
</ | </ | ||
Line 58: | Line 58: | ||
<code json> | <code json> | ||
{ | { | ||
- | " | + | |
- | " | + | " |
- | " | + | " |
} | } | ||
</ | </ | ||
Line 66: | Line 66: | ||
== Unsuccessful Response == | == Unsuccessful Response == | ||
Example response of unsuccessful authentication: | Example response of unsuccessful authentication: | ||
- | < | + | < |
{ | { | ||
- | “errors”: | + | |
- | { | + | { |
- | “code”: 401, | + | “code”: 401, |
- | “message”: | + | “message”: |
- | address and password.” | + | address and password.” |
- | } | + | } |
- | ], | + | ], |
- | " | + | " |
- | “result”: | + | “result”: |
} | } | ||
</ | </ | ||
==== How to send authenticated http requests ==== | ==== How to send authenticated http requests ==== | ||
- | Each request to the API must be authenticated using the cookie the / | + | Each request to any API endpoint has to be authenticated using the cookie |
=== Examples === | === Examples === | ||
Line 89: | Line 89: | ||
<code jquery> | <code jquery> | ||
$jq.ajax({ | $jq.ajax({ | ||
- | | + | |
- | url: ' | + | url: ' |
- | contentType: | + | contentType: |
- | dataType: ' | + | dataType: ' |
- | success: function(data) { | + | success: function(data) { |
- | console.log(data); | + | console.log(data); |
- | }, | + | }, |
- | error: function(data) { console.log(data); | + | error: function(data) { console.log(data); |
}); | }); | ||
</ | </ | ||
Line 104: | Line 104: | ||
Example Python request: | Example Python request: | ||
<code python> | <code python> | ||
- | The cookie variable was set above in the authenticate example. | + | # The cookie variable was set above in the authenticate example. |
url = " | url = " | ||
req = requests.get(url, | req = requests.get(url, |