REST postBody with postFormat XML

  • Christopher Steinbach
        5 years ago #15698

        Hi,

        is it possible to do a post request with a XML body? Or ist only JSON and PLAIN supported?

        What happens if I set postFormat to XML and pass a XML string to postBody?

        Thanks in advance.

        Christopher

        Chris Bouveret
            Has successfully completed the online course Introduction
            Has successfully completed the online course Intermediate (200)
            Has successfully completed the online course Advanced (300)
            Has successfully completed the online course Basics (100)
            Has successfully completed the online course Advanced (320)
            Has successfully completed the Intermediate Certification
            Has successfully completed the Advanced Certification
          5 years ago #15741
          Up
          0
          Down
          ::

          Hi there,

          there is a dedicated postFormat for XML so there should be no problem in doing post requests with XML postBody. This is also documented here:

          App Builder Guide

          Hope that helps

          Christopher Steinbach
              5 years ago #15911
              Up
              0
              Down
              ::

              That’s right. There is a XML postFormat property. But is XML-String accepted for the postBody? The documentation says only JSON:

              postBody (optional): a JSON defining the post body. If postBody PLAIN is selected, a string JSON representation of the key/value list will be send to the REST Endpoint

              Can you provide an example how to send a post request with XML Body?

              Christopher Steinbach
                  5 years ago #15912
                  Up
                  0
                  Down
                  ::

                  That’s right. There is a XML postFormat property. But is XML-String accepted for the postBody? The documentation says only JSON:

                  postBody (optional): a JSON defining the post body. If postBody PLAIN is selected, a string JSON representation of the key/value list will be send to the REST Endpoint

                  Can you provide an example how to send a post request with XML Body?

                  Satish
                      1 year ago #35327
                      Up
                      0
                      Down
                      ::

                      Hi,

                      I am exporting xml file from Simplifier Application and bydefault it is exporting in UTF-8 encoding. How we change this encoding to ANSI ?

                      Thanks !

                      Jennifer Häfner
                          Has successfully completed the online course Intermediate (200)
                          Has successfully completed the online course Advanced (300)
                          Has successfully completed the online course Basics (100)
                          Has successfully completed the online course Advanced (310)
                          Has successfully completed the online course Advanced (320)
                          Has successfully completed the Intermediate Certification
                          Has successfully completed the Advanced Certification
                        1 year ago #35415
                        Up
                        0
                        Down
                        ::

                        Hi Satish,

                        can you describe what exactly you are doing to export the XML file and what elements (connectors etc.) you are using?

                        Satish
                            1 year ago #35851
                            Up
                            0
                            Down
                            ::

                            Hi Jennifer,

                            I am using the following code snippet fro xml generation :

                            var dataToExport = this.getGlobals().getVar(“dataToExport”);
                            var selectedSerialNumber = this.getGlobals().getVar(“selectedSerialNumber”);
                            var xmlBase64 = this.getGlobals().getVar(“xmlBase64″);
                            var inputJSON = ‘{}’;
                            var that = this;

                            var parsedInput = JSON.parse(inputJSON);
                            parsedInput = dataToExport;

                            function OBJtoXML(obj) {
                            var xml = ”;

                            for (var prop in obj) {
                            if (obj[prop] instanceof Array) {
                            for (var array in obj[prop]) {
                            xml += ‘<‘ + prop + ‘>’;
                            xml += OBJtoXML(new Object(obj[prop][array]));
                            xml += ‘</’ + prop + ‘>’;
                            }
                            } else {
                            xml += ‘<‘ + prop + ‘>’;
                            typeof obj[prop] == ‘object’ ? xml += OBJtoXML(new Object(obj[prop])) : xml += obj[prop];
                            xml += ‘</’ + prop + ‘>’;
                            }
                            }

                            xml = xml.replace(/<\/?[0-9]{1,}>/g, ”);
                            return xml;

                            }
                            // var output = ‘<?xml version=”1.0″ encoding=”ISO8859-1″ standalone=”no”?>’;

                            console.log(OBJtoXML(parsedInput));

                            var output = `<?xml version=”1.0″ encoding=”ISO8859-1″ standalone=”no”?>
                            <Austauschdatei>
                            <Version>1.0.0</Version>
                            <!–Version der Austauschdatei–>
                            <Austauschflag>2</Austauschflag>
                            <!–Austauschflag zwischen CATS und Sitace–>`;
                            output += OBJtoXML(parsedInput);
                            output += </Austauschdatei>;

                            that.getGlobals().setVar(“xmlBase64”, btoa(output));

                            var filename = “austausch_”+selectedSerialNumber+”.xml”;
                            var pom = document.createElement(‘a’);
                            var bb = new Blob([output], {type: ‘text/plain;charset=ANSI;’});

                            pom.setAttribute(‘href’, window.URL.createObjectURL(bb));
                            pom.setAttribute(‘download’, filename);

                            pom.dataset.downloadurl = [‘text/plain;charset=ANSI;’, pom.download, pom.href].join(‘:’);
                            pom.draggable = true;
                            pom.classList.add(‘dragout’);

                            pom.click();

                            Alex K
                                Has successfully completed the online course Intermediate (200)
                                Has successfully completed the online course Advanced (300)
                                Has successfully completed the online course Basics (100)
                                Has successfully completed the online course Advanced (310)
                                Has successfully completed the online course Advanced (320)
                              1 year ago #36254
                              Up
                              0
                              Down
                              ::

                              Is there any possibility to make a POST without even postFormat declared?
                              In curl this is possible, but trying to create a POST without postFormat results in an error.

                              Reason to this is:

                              once selecting any kind of “Format”, the Posted File-format is declared preemtively. You cannot change it.
                              But what happens if the API in the background only allows Images or Datatypes like .xls or .pdf only?
                              This will 100% always result in ERROR.

                              Maybe implement more ways to post data?

                              Jennifer Häfner
                                  Has successfully completed the online course Intermediate (200)
                                  Has successfully completed the online course Advanced (300)
                                  Has successfully completed the online course Basics (100)
                                  Has successfully completed the online course Advanced (310)
                                  Has successfully completed the online course Advanced (320)
                                  Has successfully completed the Intermediate Certification
                                  Has successfully completed the Advanced Certification
                                1 year ago #36570
                                Up
                                0
                                Down
                                ::

                                Hi Satish,

                                Try to encode your XML in the format ‘window-1252’:

                                <?xml version="1.0" encoding="windows-1252" standalone="no"?>

                                If does not work for you, you can try the solution proposed in this thread, with a modified TextEncoder to create the blob: https://stackoverflow.com/questions/44135861/javascript-csv-text-download-in-ansi-windows-1252

                                However, I have not tested this solution.

                                Jennifer Häfner
                                    Has successfully completed the online course Intermediate (200)
                                    Has successfully completed the online course Advanced (300)
                                    Has successfully completed the online course Basics (100)
                                    Has successfully completed the online course Advanced (310)
                                    Has successfully completed the online course Advanced (320)
                                    Has successfully completed the Intermediate Certification
                                    Has successfully completed the Advanced Certification
                                  1 year ago #36572
                                  Up
                                  0
                                  Down
                                  ::

                                  Alex, regarding your comment: it is true that currently, the options for the postFormat are limited and indeed, in some use cases, it won’t be possible to use Simplifier’s REST connector.

                                  In these cases, we have to work with client-side XHR / ajax calls. We are planning to add more functionality to the REST connector in the future, but I cannot tell you more detailed information when the new functionality will be available.

                                Viewing 10 posts - 1 through 10 (of 10 total)

                                You must be logged in to reply to this topic.