9 Replies Latest reply on Sep 27, 2017 4:21 AM by carlesc RSS
    3studio Newbie

    Rest API Service problem from javascript



    I'm trying to create a function call to a service with javascript.


    This is my code:

    var data = "{\n\t\"input\":{\n\t\t\"space\": \"Hki Pa A 109\",\n\t\t\"type\": \"TEMP\"\n\t}\t\n}";

    var xhr = new XMLHttpRequest();

    xhr.withCredentials = true;


    xhr.addEventListener("readystatechange", function () {

      if (this.readyState === 4) {





    xhr.open("POST", "https://server-address/Thingworx/Things/PWIMAPI/Services/GetMeasurementPoints");

    xhr.setRequestHeader("accept", "application/json");

    xhr.setRequestHeader("content-type", "application/json");

    xhr.setRequestHeader("appkey", "my-app-key");

    xhr.setRequestHeader("cache-control", "no-cache");






    If I run this in postman it returns the correct json-content, but when I run it in a HTML-file on the server I get:

    Status Code:

    401 Unauthorized


    Have anyone had a similar problem before? Any suggestion how to solve this?