• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Accessing API via php script

    Dashboard Designer & Custom AngularJS Pages
    3
    4
    2.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      dmsmith
      last edited by

      Hi Joel, Phil,

      Been trying to get a listing of all of a given data point via the swagger API: /v1/point-values/{xid}/latest

      Given there are several hundred entries that I need a response for I am trying to script the process but keep running into the issue of "failed to open stream: HTTP request failed! HTTP/1.1 403 Access Denied" even though a copy & paste of the string into a browser works perfectly.

      The script in question is very simple:

      <?php
      $dpval = 2; //up to 321
      $dpnum = str_pad($dpval, 16, "0", STR_PAD_LEFT);
      $dpstring = "DP_HGU1_2_UII_$dpnum";
      $url = "http://<ip.address>:8080/rest/v1/point-values/$dpstring/latest?useRendered=true&unitConversion=false&limit=100&useCache=true";

      while ($dpval <= 321) {
      echo $dpstring;
      echo "<br>";
      echo file_get_contents($url);
      echo "<br>";
      echo "<br>";
      $dpval++;
      }
      ?>

      Have also tried numerous variations with various permutations with fopen and stream_context_create.

      Cheers,

      David

      1 Reply Last reply Reply Quote 0
      • phildunlapP
        phildunlap
        last edited by

        Hi David,

        This is probably caused by the security token that is issued to your browser in a cookie at login. If you make a login via the API this XSRF token will be returned in the response to the successful login, with the header X-XSRF-TOKEN and should be included in all subsequent REST API requests.

        Swagger is only the page at http://mango:port/swagger if swagger=true in env.properties. It's an automatically generated API explorer.

        1 Reply Last reply Reply Quote 0
        • T
          thewizardguy
          last edited by

          You can do it. Use GuzzleHttp, mess around with Swagger for a bit and be sure to take advantage of the Cookie feature.

          YOU NEED TO ENABLE CORS ON YOUR MANGO INSTALLATION OR IT WILL NEVER WORK.

          1 Reply Last reply Reply Quote 0
          • phildunlapP
            phildunlap
            last edited by

            http://infiniteautomation.com/forum/topic/1944/mango-rest-api-special-key/2

            Has information on enabling CORS

            1 Reply Last reply Reply Quote 0
            • First post
              Last post