• 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

    JSON RETRIEVER: Error 400

    User help
    3
    5
    1.2k
    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.
    • Z
      zaaphod
      last edited by zaaphod

      I am having issues with JSON HTTP retriever and need a little help.

      I have set up the data source and data point. I get error 'Invalid Response 400' trying to configure the data source, I know it's down to configuration I am just not sure how it is set up, struggling to see it in the documentation. I know my API requests work out with Mango so I was looking for the advise on how I should set it up.

      When testing GET requests before i attempted to link it to Mango i had it set up like so.

      Endpoint: http://86.156.98.233:80/api/slot/0/io/di

      Headers:

      • Accept - vdn.dac.v1
      • Content-Type - application/json

      That will pull all my inputs of the device and can use the following to pick out each input for the specific signal.

      • 'http://86.156.98.233:80/api/slot/0/io/di/0/diStatus'

      Here is how I set it up.

      alt text

      I i get the error 400 when trying to connect, I beleive it is an issue to do with theh headers on the API get request. Where can i edit the headers? Any help would be much appreciated.

      Thanks

      1 Reply Last reply Reply Quote 0
      • MattFoxM
        MattFox
        last edited by MattFox

        It would likely be better if you used the mango javascript httpRequestBuilder to make your own GET query for your custom headers. Then use that to populate a meta data point or if needs be, use a scripting datasource and save all of your values to the points inside the scripted datasource.

        Refer to this help I gave Nurr not too long ago and use that to build your get query:
        https://forum.infiniteautomation.com/topic/4834/how-to-get-json-data-via-api/2

        Fox

        Do not follow where the path may lead; go instead where there is no path.
        And leave a trail - Muriel Strode

        1 Reply Last reply Reply Quote 0
        • CraigWebC
          CraigWeb
          last edited by

          I agree with MattFox, the JSON retriever is not very flexible and only works on very basic APIs.
          Are you using the Moxa ioLogik? If so you might want to look into using SNMP to communicate with it.

          1 Reply Last reply Reply Quote 0
          • Z
            zaaphod
            last edited by zaaphod

            Thanks for the reply's.

            I had a go with the scripts but running into issues with the callback. I am getting 'TypeError: Cannot read property "length" from undefined at line: 16'.

            var foxesCBHandler = function(status, headers, content)
            {
               var data = JSON.parse(content);
               data = data.result; //lets get the info we want.
                for (var pnt in CONTEXT_POINTS) //list of points in context
                {
                    for(var i=0; i<data.length; i++) //loop through available values.
                    {
                        if(this[pnt].xid === data[ i ].deviceName) //items match
                        {
                            this[pnt].set(data[ i ].diStatus, Date.parse(data[ i ].readDate) ); //set value and time
                            break; //finished, next context pt!
                         }
                    }
                }
            }
            

            I'm rather new to javascript so not sure what the issue is there. The JSON i am requesting is:

            {"slot":0,"io":{"di":[
            {"diIndex":0,"diMode":0,"diStatus":0},
            {"diIndex":1,"diMode":0,"diStatus":0},
            {"diIndex":2,"diMode":0,"diStatus":0},
            {"diIndex":3,"diMode":0,"diStatus":0}
            ]}}
            

            I am just looking to pull the DiStatus.

            Matt, i am using the Moxa IoLogic. I can give that a look although have never used SNMP before. Have you set them up before with SNMP in the past? I'm not too sure of the configuration for it.

            Zaphod

            1 Reply Last reply Reply Quote 0
            • MattFoxM
              MattFox
              last edited by

              @zaaphod said in JSON RETRIEVER: Error 400:

              {"slot":0,"io":{"di":[
              {"diIndex":0,"diMode":0,"diStatus":0},
              {"diIndex":1,"diMode":0,"diStatus":0},
              {"diIndex":2,"diMode":0,"diStatus":0},
              {"diIndex":3,"diMode":0,"diStatus":0}
              ]}}

              You're already 90% of the way there.
              I'd argue your code will be something like this since there is no "result" property in your incoming data.

              
                 var data = JSON.parse(content);
                 data = data.io.di; //lets get the info we want.
                  
              

              However, you still need to be able to have a means to link what diIndex is what point.
              If you have the points configured with a specific XID or naming convention, we can use that to map it all together.

              Fox

              Do not follow where the path may lead; go instead where there is no path.
              And leave a trail - Muriel Strode

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