Calling APIs in Custom Content

Admin Custom Content ($http)

For Admin custom content, you can use the Angular $http method to call your APIs. $http does the work of automatically adding the user's authentication token to the request.



Web Office and Shop Custom Content ($RestService)

Custom content for Web Office and eCommerce Shop work a little differently by using $RestService. $RestService is a list of functions with every single endpoint the DirectScale sites call. All the functions within $RestService primarily call makeRequest. makeRequest does the work of adding an authorization header to the request, wrapping around $http to make the actual web request. This is how Web Office and eCommerce Shop pass in the logged-in user information.

If you used $http in Web Office or eCommerce Shop custom content, the server would return a 403 error (access denied), so you have to use the $RestService.


Generic Calls

For any API endpoints that don't already have a defined function in $RestService with which to call them, you can use the following generic $RestService functions:

  • Get

    • requestUrl - Endpoint URL
  • Post

    • requestUrl - Endpoint URL
    • requestParameterData - The JSON object that you want to post. You can omit this parameter when there is nothing to send on the request.

Custom APIs Calls

For the Custom APIs you've created in a Client Web Application, the functions to use differ for Web Office and eCommerce Shop. There are a few functions that will work, but the following are the simplest to use:
For Web Office:

  • DynamicV3Proxy

    • methodName - Request URL. Automatically prepends /Proxy/ to the URL. Read more about API Proxy.
    • request - The JSON object that you want to post. You can omit this parameter when there is nothing to send on the request.
$RestService.DynamicV3Proxy('report/skuperformance?timeout=60000', request).then(function (result) {

For eCommerce Shop:

  • GenericV3Post - Because the *eCommerce Shop experience doesn't rely on the users being logged in, using the unauthenticated endpoints is usually more appropriate. Read more about API Proxy.

    • request - The JSON object that you want to post. You can omit this parameter when there is nothing to send on the request.
    • method - Request URL. You must include the relevant Proxy URL root path (/AnonysmousProxy/ or /AnonysmousProxySimple/).