2 Replies Latest reply on Apr 28, 2017 4:00 AM by jbenethuiliere RSS
    jbenethuiliere Newbie

    Send value to a Thingworx service from another Thingworx service using .PostJSON

    I've been stuck for quite some time already trying to perform the action described in the title.

    Trouble.png

    I tried to explain my process with this picture. I'm calling manually the "service 1", INPUT : NONE, OUTPUT: result (string) .

    The result variable seems to be empty, and this is certainly the problem here.

    The boolean 'serviceCalled' is set to true, so the request is calling 'service 2'.

    The JSON content is set to '{}', so either 'service 2' receive nothing or it's receiving an empty json.

    'service 2' as an INPUT: 'content' and an OUTPUT: 'result' (TEXT) returning undefined.

     

    The thing is that I tried to send whatever I could think of into the "content: X" property of "service 1" but it's always returning nothing.

    I don't think I can use another method because in the end I won't just change a thing's property in thingworx but I want to send 'service 1''s request to another device.

    I linked the picture in case it prints to small on the forum.

     

    I'll be waiting for your help,

    Julien BENETHUILIERE 

      • Re: Send value to a Thingworx service from another Thingworx service using .PostJSON
        kmoon Apprentice

        Hi Julien,

         

        As far as I understood so far, you are trying to call a service called "service2" on a second TWX server and the service has a input parameter which is a JSON type. So, you created a service called "service1" on a first TWX server and used a PostJSON snippet to call the service and get a result as a JSON format, right? (I am not still able to understand why you want to have a JSON return value from the "service2" though).

         

        When you use the "PostJSON" snippet in your script, you can think that you are passing "content" parameter to another ThingWorx server as a JSON format. But as a matter of fact, when your service2 gets called from the service1, it will get parameters like "var"(you can't use this as a parameter name though) and its value "du texte". So, basically the content parameter of the "PostJSON" snippet is designed to pass parameters with key and value pairs, not for one parameter of JSON format.

         

        Daniel

          • Re: Send value to a Thingworx service from another Thingworx service using .PostJSON
            jbenethuiliere Newbie

            Both services are on the same TWX server.
            'service 2' is just for the purpose of testing that 'service 1' is sending the good values.
            Latter, 'service 2' will be deleted and I will change the URL to send my data to another device.

            This device is not yet accessible by me, so I have to use 'service 2' now to "debug".

             

            From what you said, I tried to put " content: {'content': {'something': 'some content'}}, " in my code and it's finally working.

            I guess I didn't find any other example because my process is not something useful in a finished application.

             

            I will have one last question:

            I understand now that the content input of 'service 2' is catching the 'content' parameter of my JSON, but what is 'service 2' (so my future device) actually receiving ?

            {'content': {'something': 'some content'}} or {'something': 'some content'} ?