1 2 Previous Next 17 Replies Latest reply on Oct 26, 2016 12:51 AM by monkeybreadsoftware

    CURL Post (soap) using MBS Plugin- specify output

    mchancevet@gmail.com

      Hello,

      I'm quite new to CURL functions - all a bit confusing.

      I'm trying to integrate an Hosted FM solution to a 3rd party API for logisitics

       

      Here is the template for my POST

       

      curl -v -X POST -d@GenerateLabels.xml https://webapi.auspost.com.au/soap/LodgementManagement_MerchantTest_v1 --header "Content-Type: application/soap+xml;charset=UTF-8;action=\"generateLabel\"" --insecure --user lps_merchant_testing:LPSprodtesting@1 2>out2.txt >out1.xml

       

      I am using MBS Plugin with the following functions

       

       

      MBS (CURL.New)

      SetOptionVerbose

      SetOptionPost

      SetOptionURL

      SetOptionUserName

      SetOptionPassword

      SetOptionHTTPHeader

      SetOptionInputFile (order.xml)

      SetOptionPostFields ("2>out2.txt >out1.xml")

      SetPerform

       

      I'm still getting plenty of errors and no 'out2.txt or out1.xml as a result.

       

      How can I add the "2>out2.txt >out1.xml" correctly if this is incorrect, Is it a post field?

       

      Is it best to pass the input XML file as a file or as a text string as a Post field?

       

      If so should I use this function twice or can it handle 2 fields as a list?

       

      Thanks,

       

      Morgan

        • 1. Re: CURL Post (soap) using MBS Plugin- specify output
          monkeybreadsoftware

          you may want to read his:

          http://www.mbs-plugins.com/archive/2013-09-26/CURL_from_command_line_to_Plug/monkeybreadsoftware_blog_filemaker

           

          Please use only SetOptionPostFields here and pass the content of the XML file. That's best for SOAP queries.

          2>out2.txt >out1.xml would simply redirect output for normal text to out1.xml and errors to out2.xml. But with our plugin we normally just collect values in memory.

           

          You should query CURL.GetDebugAsText after transfer.

          And CURL.GetResultAsText to get the answer.

           

          -v for verbose is always an.

          -X POST is CURL.SetOptionPost

          1 of 1 people found this helpful
          • 2. Re: CURL Post (soap) using MBS Plugin- specify output
            mchancevet@gmail.com

            Here is the GetResultAsText

             

            <?xml version="1.0" encoding="UTF-8"?>

            <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

                <soapenv:Body>

                    <soapenv:Fault>

                        <faultcode>soapenv:Server</faultcode>

                        <faultstring>Policy Falsified</faultstring>

                        <faultactor>https://webapi.auspost.com.au/soap/LodgementManagement_MerchantTest_v1</faultactor>

                        <detail>

                            <l7:policyResult

                                status="Service Not Found.  The request may have been sent to an invalid URL, or intended for an unsupported operation." xmlns:l7="http://www.layer7tech.com/ws/policy/fault"/>

                        </detail>

                    </soapenv:Fault>

                </soapenv:Body>

            </soapenv:Envelope>

             

            Here is the GetDebugAsText

             

              Trying 155.144.101.64...

            Connected to webapi.auspost.com.au (155.144.101.64) port 443 (#0)

            ALPN, offering http/1.1

            Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH

            TLSv1.2 (OUT), TLS header, Certificate Status (22):

            TLSv1.2 (OUT), TLS handshake, Client hello (1):

            TLSv1.0 (IN), TLS handshake, Server hello (2):

            TLSv1.0 (IN), TLS handshake, Certificate (11):

            TLSv1.0 (IN), TLS handshake, Server key exchange (12):

            TLSv1.0 (IN), TLS handshake, Request CERT (13):

            TLSv1.0 (IN), TLS handshake, Server finished (14):

            TLSv1.0 (OUT), TLS handshake, Certificate (11):

            TLSv1.0 (OUT), TLS handshake, Client key exchange (16):

            TLSv1.0 (OUT), TLS change cipher, Client hello (1):

            TLSv1.0 (OUT), TLS handshake, Finished (20):

            TLSv1.0 (IN), TLS change cipher, Client hello (1):

            TLSv1.0 (IN), TLS handshake, Finished (20):

            SSL connection using TLSv1.0 / ECDHE-RSA-AES256-SHA

            ALPN, server did not agree to a protocol

            Server certificate:

              subject: jurisdictionC=AU; businessCategory=Private Organization; serialNumber=28 864 970 579; C=AU; ST=Victoria; L=Melbourne; O=Australian Postal Corporation; CN=webapi.auspost.com.au

              start date: 2015-10-19 00:00:00 GMT

              expire date: 2016-12-14 23:59:59 GMT

              issuer: C=US; O=Symantec Corporation; OU=Symantec Trust Network; CN=Symantec Class 3 EV SSL SGC CA - G2

              SSL certificate verify result: self signed certificate in certificate chain (19), continuing anyway.

            Server auth using Basic with user 'lps_merchant_testing'

            POST /soap/LodgementManagement_MerchantTest_v1 HTTP/1.1

            Host: webapi.auspost.com.au

            Authorization: Basic bHBzX21lcmNoYW50X3Rlc3Rpbmc6TFBTcHJvZHRlc3RpbmdAMQ==

            Accept: */*

            Content-Type: application/x-www-form-urlencoded

            Expect: 100-continue

             

            HTTP/1.1 100 Continue

            HTTP/1.1 500 Internal Server Error

            Server: Apache-Coyote/1.1

            Content-Type: text/xml;charset=utf-8

            Content-Length: 710

            Date: Tue, 24 May 2016 11:42:44 GMT

            Connection: close

             

            <?xml version="1.0" encoding="UTF-8"?>

            <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

                <soapenv:Body>

                    <soapenv:Fault>

                        <faultcode>soapenv:Server</faultcode>

                        <faultstring>Policy Falsified</faultstring>

                        <faultactor>https://webapi.auspost.com.au/soap/LodgementManagement_MerchantTest_v1</faultactor>

                        <detail>

                            <l7:policyResult

                                status="Service Not Found.  The request may have been sent to an invalid URL, or intended for an unsupported operation." xmlns:l7="http://www.layer7tech.com/ws/policy/fault"/>

                        </detail>

                    </soapenv:Fault>

                </soapenv:Body>

            </soapenv:Envelope>

            Closing connection 0

            TLSv1.0 (OUT), TLS alert, Client hello (1):

            • 3. Re: CURL Post (soap) using MBS Plugin- specify output
              monkeybreadsoftware

              You call SetOptionHTTPHeader?

               

              Some need SOAPAction header to know what to do.

               

              1 of 1 people found this helpful
              • 4. Re: CURL Post (soap) using MBS Plugin- specify output
                mchancevet@gmail.com

                MBS("CURL.SetOptionHTTPHeader";"Content-Type: application/soap+xml; charset=UTF-8;action=\"generateLabel\"")

                 

                I called this one. Maybe I should call SOAPAction as well?

                With what content if any?

                • 5. Re: CURL Post (soap) using MBS Plugin- specify output
                  mchancevet@gmail.com

                  Maybe the problem is with my XML?

                   

                  I generated it using FM native text functions ( plus a custom function I made to create and close tags)

                   

                  Mine has no indentation. But I note the API response XML in the debugging text field has indentation.

                  Maybe it has formatting issues.

                  is that a problem?

                  • 6. Re: CURL Post (soap) using MBS Plugin- specify output
                    mchancevet@gmail.com

                    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"xmlns:gen="http://www.auspost.com.au/Schema/ProductandServiceFulfilment/LodgementManagement/generateLabel:v1">

                    <soap:Header/>

                    <soap:Body>

                    <gen:get>

                    <Generate>

                    <InterfaceHeader>

                    <InterfaceName>generateLabel</InterfaceName>

                    <InterfaceVersion>1.0</InterfaceVersion>

                    <MessageType>Request</MessageType>

                    <BusinessReferenceID>generateLabel20160524223855QTC</BusinessReferenceID>

                    <SourceSystemID>L7</SourceSystemID>

                    <Timestamp>2016-05-24T20:38:56</Timestamp>

                    </InterfaceHeader>

                    <ServiceHeader>

                    <RequestType>PDF</RequestType>

                    <RequesterId>20429653</RequesterId>

                    <LabelMessage></LabelMessage>

                    </ServiceHeader>

                    <LabelGroup>

                    <Layout>A4-1pp</Layout>

                    <Branding>false</Branding>

                    <LeftOffset>16</LeftOffset>

                    <TopOffset>16</TopOffset>

                    <Label>

                    <TemplateName>EPARCEL</TemplateName>

                    <InternationalPrintList>All</InternationalPrintList>

                    <Source>GDH</Source>

                    <OrderRef>Ord333</OrderRef>

                    <CustomerRef1>RB9170524</CustomerRef1>

                    <TotalArticles>1</TotalArticles>

                    <DeliverySignatureCapture>Always</DeliverySignatureCapture>

                    <PickupSignatureCapture>True</PickupSignatureCapture>

                    <PostagePaidIndicator>True</PostagePaidIndicator>

                    <ParcelCharacteristics>

                    <ProductClassification>32</ProductClassification>

                    <DangerousGoodsIndicator>false</DangerousGoodsIndicator>

                    <Contents>

                    <ContentWeight>2.4</ContentWeight>

                    </Contents>

                    <Height>13</Height>

                    <Length>13</Length>

                    <Width>13</Width>

                    <Weight>2.45</Weight>

                    </ParcelCharecteristics>

                    <RecipientAddress>

                    <Name>Morgan Chance</Name>

                    <AddressLine1>139 Dickson Way</AddressLine1>

                    <Suburb>Point Lookout</Suburb>

                    <State>Queensland</State>

                    <PostCode>4183</PostCode>

                    <Country>AUSTRALIA</Country>

                    <CountryCode>NZ</CountryCode>

                    <Phone>0411539067</Phone>

                    </RecipientAddress>

                    <SenderAddress>

                    <Name>Sam Pinney</Name>

                    <CompanyName>RedBubble</CompanyName>

                    <AddressLine1>Level 3</AddressLine1>

                    <AddressLine2>271 Collins St</AddressLine2>

                    <Suburb>Melbourne</Suburb>

                    <State>Victoria</State>

                    <PostCode>3000</PostCode>

                    <CountryCode>NZ</CountryCode>

                    <Phone>0402842472</Phone>

                    <InternationalSenderSignatureName>Sam Fraser</InternationalSenderSignatureName>

                    </SenderAddress>

                    </Label>

                    </LabelGroup>

                    </Generate>

                    </gen:get>

                    </soap:body>

                    </soap:Envelope>

                    • 7. Re: CURL Post (soap) using MBS Plugin- specify output
                      monkeybreadsoftware

                      ParcelCharacteristics has no closing tag.

                      1 of 1 people found this helpful
                      • 9. Re: CURL Post (soap) using MBS Plugin- specify output
                        mchancevet@gmail.com

                        Do you think spatial formatting could be a factor?

                         

                        I tried with an XML string the API provider tech corrected off one I provide him from my system. Same result with his xml (no useful response) and he only applied indentation to half of the xml so I assumed it was mostly for human readability. My research on whitespace in XML and XML formatting has been equivocal on this issue.

                        So I don't have a clear idea on the formatting - it seems to be a human readability function to me. Although some APIs seem to be able to selectively specify whitespace constraints on XML strings?

                        confused!

                         

                        Thanks

                        Morgan

                        • 10. Re: CURL Post (soap) using MBS Plugin- specify output
                          monkeybreadsoftware

                          No. They are not the same.

                          Please check for spelling mistakes.

                          • 11. Re: CURL Post (soap) using MBS Plugin- specify output
                            monkeybreadsoftware

                            You can send me your test project and I can take a look.

                             

                            Sometimes it's better to pay an hour for support than spending all day on such an issue.

                            • 12. Re: CURL Post (soap) using MBS Plugin- specify output
                              mchancevet@gmail.com

                              Hello again,

                              Well I have learned a lot from this,

                              My XML was seriously compromised. Thanks Christian for pointing out the first of many syntax errors.

                              Any other newbie out there - there are many free online XML syntax validators - I used w3 schools web based validator.

                              But that was not the end of my challenge.

                              The XML was syntactically corrected but still contained many element names and content syntax that did not suit the API's XML Parser - It could not make sense of it because my data was wrong (capitalisation errors mostly).

                              After a lot of to and fro - I finally have an XML that the API techs can pass in and generate a meaningful response ( in this case a pdf shipping label file, base 64 encoded)

                              I still can't POST the XML to the API for reason's we don't yet understand. but at least we know the XML is not at fault.

                               

                              I still have plenty of questions

                               

                              curl -v -X POST -d@GenerateLabels.xml https://webapi.auspost.com.au/soap/LodgementManagement_MerchantTest_v1 --header "Content-Type: application/soap+xml;charset=UTF-8;action=\"generateLabel\"" --insecure --user lps_merchant_testing:LPSprodtesting@1 2>out2.txt >out1.xml

                               

                              In the above curl post there are various elements or curl structures such as -v or -d

                              These represent options or data or headers etc. I've found various resources that describe these and curl is somewhat clearer to me ( for other newbies - in the terminal or command line type 'man curl' - you'll get a great manual on curl),

                               

                              But what about 2>out2txt >out1.xml ?- ok I know now what this does. It creates an output and a dialogue (debug) file in the root directory. However how does it fit into the CURL structure? it doesn't have any tag like -d or -X. Is it just a command in the command line? How would one add it to a CURL post using a plugin like MBS? in the above example it's not in the -d section.

                               

                              Here's another one

                              The above example contains a data element -d@GenerateLabels.xml that points to a file in the root directory "GenerateLabel.xml". great!

                              But we could also input the same data as a text string '-d "<SOME XML...........>....." this seems fine in a plugin function like MBS (SetOptionPostFields) (i've only made this work with JSON so far). But if I try the same trick using curl commands in terminal - it spits dummies and complains about return carriages or line breaks etc, of which there are ample.

                               

                              Still puzzling it out.

                              Thanks,

                              Morgan

                              • 13. Re: CURL Post (soap) using MBS Plugin- specify output
                                monkeybreadsoftware

                                -v is CURL.SetOptionVerbose in our plugin.

                                -d passes data to the transfer. That is same as CURL.SetOptionPostFields

                                 

                                2> and > do redirect output to files. That's what our plugin does in memory and you query result with CURL.GetResultAsText or CURL.GetDebugAsText.

                                 

                                 

                                If you have big trouble, maybe you put it in a small example database and send me for review?

                                • 14. Re: CURL Post (soap) using MBS Plugin- specify output
                                  jaybhavsar

                                  Hi,

                                   

                                   

                                  I am getting same issue.

                                  Can you please help me?

                                   

                                   

                                  1 2 Previous Next