Working with REST apis

Hi erveryone,

We are currently in the process of rolling SDL WorldServer out in our organisation. We are running our tests on v. 11.0 but will probably go live with 11.1 as soon as it is available.

I am thinking of using the REST API to access some data. However, I am quite new to REST APIs in general. I am able to set up the connection to the server but it stops there. I am not sure how I should proceed to read the response and retrieve the sessionID. The response looks like formatted HTML and not really like JSON content.

The current documentation of the API does not provide samples on how to implement the API. I wanted to ask if some of you maybe have samples or code parts they would agree to share with me. it would be a great help. Code can be in c# or even javascript.

Thanks in advance to those who will reply.

Regards,

Laurent

Parents Reply
  • Hi Laurent,

    the API is (as you already know) REST based. This means that one should just be making HTTP calls with correct verbs (according to the documentation) no matter which tools / programming languages are used.

    The base URL for the REST API is: http(s)://{your-server-name}:{port-number}/ws-api/v1
    The endpoints are then added to to that base URL and one has to make sure that the http request has a Content-Type header set to "application/json".

    For example, to login you have to make a POST request to {BASE_URL}/login, set Content-Type to application/json and in the body of the request send following json:

    {
    "username":"your-username",
    "password":"your-password"
    }

    as a response you would get something similar to the following json:
    {
    "sessionId": "956580144",
    "expirationTime": "",
    "userDetails": {
    "fullName": "Admin",
    "fingerprint": "2b35927d-cfef-4884-80bd-9d73ca849965",
    "language": {
    "id": 1033,
    "languageCode": "en",
    "countryCode": "US",
    "locale": "en_US_English (United States)"
    },
    "regionalSettingsLocale": "en_US_English (United States)"
    },
    "loginOutcome": "LOGIN_SUCCEEDED",
    "lastUpdateTime": 1465461211916,
    "daysToPwdExpire": -1
    }

    What's important is the session id since this is used as session token for all the subsequent requests.

    For example, if I wanted to get a list of workflows configured on the server I would then make a GET request
    using the session id from previous request as token parameter:

    GET {BASE_URL}/workflows?token=956580144

    and this gets you back json that would look something like this:

    {
    "items": [
    {
    "id": 1002,
    "name": "Simple WF with Review",
    "description": "",
    "type": "ASSET",
    "steps": [
    {
    "id": 1011,
    "type": "START",
    "name": "Start",

    .... the rest json response left out
    }

    To make these REST calls you can use any REST Client / library you want (e.g. in C# that would be HttpClient from System.Net.Http namespace, have a look here: msdn.microsoft.com/.../system.net.http.httpclient(v=vs.110).aspx)

    Good example on how to call REST API from .NET, as Paul already mentioned, can be found in the GroupShareKit.NET
    (the code is freely available on GitHub: github.com/.../groupsharekit.net)

    Hope this was helpful.

    Thanks,
    Mio
Children