Using world check one API in salesforce returns 401 Unauthorized error?

We have used the API Key and API secret from postman collection. Trying to request for the group id from Salesforce returns 401 Unauthorized error. When accessed via postman we are getting the expected result but not in Salesforce. Do we need any special authorization key other than that?Need advice

Best Answer

  • brian.bourgault
    Answer ✓

    Hi @baskaran.subramanian

    There are a number of common errors developers make when first learning the WC1 API. With the same API keys and the properly coded authorization and headers it should work.

    If you're programming in C# or Java, go to Downloads->CODE EXAMPLES and download the GET & POST examples, the GET example has the proper code for the groups endpoint.

    ----

    I also have a WC1 API Overview and Quick Start video I'll be posting the Developer Community next week that may help. While the video addresses the common errors through the Postman Collection, several of the errors are generic and the likely root cause of programming errors when first developing your WC1 API solution. Also search Q&A for 401 and review the issues that were posted by other developers who's coding errors were found and corrected.

    Here's a slide from the video.

    Brian

    function generateAuthHeader(dataToSign){
    var hash = CryptoJS.HmacSHA256(dataToSign,environment["api-secret"]);
    return hash.toString(CryptoJS.enc.Base64);
    }
    var date = new Date().toGMTString();
    var dataToSign = "(request-target): get " + environment["gateway-url"] + "groups\n" +
    "host: " + environment["gateway-host"] + "\n" +
    "date: " + date;
    var hmac = generateAuthHeader(dataToSign);
    var authorisation = "Signature keyId=\"" + environment["api-key"] + "\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date\",signature=\"" + hmac + "\"";
    postman.setEnvironmentVariable("authorisation",authorisation);
    postman.setEnvironmentVariable("currentDate",date);

    image

Answers