REST API Tutorial 1: Connecting to the DSS server
Last update | November 2019 |
Environment | Any |
Language | Any HTTP is supported |
Compilers | None |
Prerequisites | DSS login, internet access |
Source code | Below |
Tutorial purpose
This tutorial explains how to request an authentication token from the DSS server.
This is the starting point and a pre-requisite for all the other tutorials.
It also illustrates how to get user information using the token, which is a way to test if it is still valid.
A Postman collection and environment are available in the downloads, but you can also enter HTTP requests manually.
Table of contents
- User authentication
- Authentication - HTTP request
- Authentication - HTTP response
- Get user information - HTTP request
- Get user information - HTTP response
User authentication
The DSS REST API requires a valid DSS username and password in order to access any of the API capabilities. These username and password are the same as those used for your DSS web GUI, FTP or DSS SOAP API credentials.
The DSS username and password are used to request an authentication token. The received token must be cached, and attached to all following requests to the DSS server.
The tokens are valid for 24 hours, after which a 401 (Unauthorized, Authentication Required) status code is returned. At that point a new token must be requested.
Authentication - HTTP request
Note: you must provide valid DSS credentials (username and password) in the body of the request.
URL:
https://hosted.datascopeapi.reuters.com/RestApi/v1/Authentication/RequestToken
Method: POST
Headers:
Prefer: respond-async
Content-Type: application/json
Body:
{
"Credentials": {
"Username": "33314",
"Password": "XXXXXXX"
}
}
Authentication - HTTP response
Status: 200 OK
Relevant headers:
Content-Type: application/json; charset=utf-8
The content is in JSON (JavaScript Object Notation) format.
Body:
{
"@odata.context": "https://hosted.datascopeapi.reuters.com/RestApi/v1/$metadata#Edm.String",
"value": "A6C451842A8FF72ECFB75DFF63AD8D03FE3D486FD1EB8EE48B296A8D469BE732DAA16356CF75BC0E349456694DAB3C650AB199C66C46016D33D5AAB1B4E44D22AD14905DAF573D21BFA771CCA58DAA63C1EF71BB488D768988A65E6A47B0F797F9DFCE8DCBBD516BAD8C33C6C629CD5B3B276D4D4A8C89ABD0A318F2B3893ED0C160B2E831A673D1AA8BA3EDE1945BA0083DADBF548EA8644CD01831AE3F5F27CF7AE06D2614792178723E005CE5DDABB4C9E6DD247B17A1775C418A009005DFF417EB2729CC61FF4021C147D9ED976A6FF02F8931F2B75ED8BCED3B1D182450"
}
The returned value is the token.
Get user information - HTTP request
Notes:
- For all requests we need to include a user token in the header of our request. That is the token we just retrieved.
- The DSS user name is set as a parameter in the path.
Let us make a request for user information. Making a simple request allows us to test the validity of a token.
URL:
https://hosted.datascopeapi.reuters.com/RestApi/v1/Users/Users(33314)
Method: GET
Headers:
Prefer: respond-async
Authorization: Token F0ABE9A3FFF2E02E10AE2765ED872C59B8CC3B40EBB61B30E295E71DE31C254B8648DB9434C2DF9299FDC668AA123501F322D99D45C8B93438063C912BC936C7B87062B0CF812138863F5D836A7B31A32DCA67EF07B3B50B2FC4978DF6F76784FDF35FCB523A8430DA93613BC5730CDC310D4D241718F9FC3F2E55465A24957CC287BDEC79046B31AD642606275AEAD76318CB221BD843348E1483670DA13968D8A242AAFCF9E13E23240C905AE46DED9EDCA9BB316B4C5C767B18DB2EA7ADD100817ADF059D01394BC6375BECAF6138C25DBA57577F0061
Get user information - HTTP response
If the token is valid, this is the response we get:
Status: 200 OK
Relevant headers:
Content-Type: application/json; charset=utf-8
Body:
{
"@odata.context": "https://hosted.datascopeapi.reuters.com/RestApi/v1/$metadata#Users/$entity",
"UserId": 33314,
"UserName": "Firstname Lastname",
"Email": "firstname.lastname@domain.com",
"Phone": "xxx-xxx-xxxx"
}
If the token is not valid, or has expired, a 401 (Unauthorized, Authentication Required) status code is returned.