1

I did a controller inside commerce cloud in order to update the order from the external Order Management Service.

Then controller inside the Commerce Cloud will receive the order details by a POST method and save the updates in the order accordingly.

The problem is that I am not able to send a request by an external resource. For any request I receive a result:

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>

<head>
    <title>401 - Authorization Required.</title>
    <link rel="STYLESHEET" type="text/css" href="/waroot/style.css">
</head>

I am sending the request to get the token in https://account.demandware.com/dwsso/oauth2/access_token and with the proper token sending the request with the token for the resource location, following the example given in https://documentation.b2c.commercecloud.salesforce.com/DOC1/index.jsp?topic=%2Fcom.demandware.dochelp%2Fcontent%2Fb2c_commerce%2Ftopics%2Fsearch_engine_optimization%2Fb2c_digital_url_syntax_without_seo.html for example: https://localhost/on/demandware.store/Sites-SiteGenesis-Site/default/Hello-World

I tried two different controllers:

server.post('Test', function (req, res, next) {
    try {
        Transaction.wrap(function () {
            // Some logic
        });
    } catch(e) {
        Logger.error('Exception "{0}"" .', e.message);
    }
    next();
});

and also a more simple aproach:

exports.Test = function(){
    response.getWriter().println('Hello World!');
};
exports.Test.public = true;

But no matter what I do I always receive the 401 - Authorization Required response.

Is there something wrong in the authentication process, controller or my resource location that I should be changing to permit the request from an third-party system to access my controller?

1 Answer 1

0

The issue seems to come from the fact that you're not returning anything in your controller.

Assuming you want to return JSON data, the res (response) argument passed to your Test function should solve the problem. Try this inside the function:

res.json({
    // Javascript object here    
});

return next();

The json() method of the res object should build and output JSON data when your controller function is called.

Have a look at the official doc for more info on the methods available for the response object in order to format the controller output.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .