WL.api

Last modified: March 13, 2015

Makes a call to the Live SDK Representational State Transfer (REST) API, for a Windows Store app or web app.

This method encapsulates a REST API request, and then calls a callback function to process the response.

Parameters

  • properties

    Required. A JSON object that contains the following properties, which are necessary to make the REST API call.

    Name

    Type

    Description

    Default Value

    path

    string

    Required. Contains the path to the REST API object. For information on specifying paths for REST objects, see REST reference.

    None

    method

    string

    Optional. An HTTP method that specifies the action required for the API call. These actions are standard REST API actions: "COPY", "GET", "MOVE", "PUT", "POST", and "DELETE".

    "GET"

    body

    object

    Optional. A JSON object that specifies the REST API request body. The body property is used only for "POST" and "PUT" requests.

    None

  • callback

    Specifies a callback function that is executed when the REST API call is complete. The callback function takes the API response object as a parameter. The response object exposes the data returned from the Live SDK, or, if an error occurs, an error property that contains the error code.

    Note Note

    Although the callback parameter is still supported, we recommend that you use the Promise object instead, which is described later in this topic.

Return value

Returns a Promiseobject. This object's then method provides the onSuccess, onError, and onProgress parameters to enable your code to handle a successful, failed, and in-progress call to the corresponding WL.api method, respectively.

Remarks

Important note Important

For Windows Store apps using JavaScript, before calling the WL.api function, your code must call either the WL.init or WL.login function with, at minimum, the required scopes for creating, reading, updating, or deleting the corresponding data. If you don't do this, the call to the WL.api function may fail. Also, this requirement applies to each webpage's current session. Therefore, if your app contains multiple webpages, each webpage must follow this requirement.

Example

function createFolder_onClick() {
    WL.login({
        scope: "wl.skydrive_update"
    }).then(
        function (response) {
            WL.api({
                path: "me/skydrive",
                method: "POST",
                body: {
                    "name": "This is a new folder",
                    "description": "A new folder"
                } 
            }).then(
                function(response) {
                    document.getElementById("infoArea").innerText = 
                        "Created folder. Name: " + response.name + ", ID: " + response.id;
                }, 
                function (responseFailed) {
                    document.getElementById("infoArea").innerText = 
                        "Error calling API: " + responseFailed.error.message;
                }
            );
        },
        function (responseFailed) {
            document.getElementById("infoArea").innerText = 
                "Error signing in: " + responseFailed.error_description;
        }
    );
}

Requirements

Library

Wl.js

Show: