webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Pub.client:http with mutiform-data

  • 1.  Pub.client:http with mutiform-data

    Posted Tue July 21, 2020 02:10 AM

    Hello webMethods Experts,

    I am using webMethods 10.3 and trying to translate a POST call from POSTMAN to webMethods pub.client:http.
    In the Headers part contains the following:

    • Authorization: {token key}
    • Accept: application/json
    • Content-Type: multipart/form-data

    In the body, it requires input as attachment like as shown below:

    Basically the files and the thread_input in body is 2 physical files:

    1. files : any pdf file.
    2. thread_input: json file.

    I dont have any problem with the Header part, but i am bit confuse how can i translate the body in pub.client:http?

    Appreciate if you have any advise.

    Thank you.

    Best Regards,
    Fanny T


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 2.  RE: Pub.client:http with mutiform-data

    Posted Tue July 21, 2020 08:28 AM

    Hi Fanny,

    Please refer the following built in services for translating the body.

    pub.flow:transportinfo & ( for getting contentStream )
    pub.mime: *** services ( for forming or reading the body from POST )

    You should be able to extract the files by using this services.

    Thanks.

    Regards,
    Firoz Nalband.


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 3.  RE: Pub.client:http with mutiform-data

    Posted Wed July 22, 2020 11:37 PM

    Hi Firoz,

    Could you elaborate more on your answer?

    Basically i have 2 files: PDF and json files. I can use service pub.file:getFile into stream form.
    Then what do you suggest the next step using:

    pub.flow:transportinfo
    pub.mime:***

    Basically i want to re-create the POSTMAN as I put in screen capture using pub.http.
    I tried to put data which contains args for files and thread_input like below:

    The files and the thread_input will the path of the files, but i doesn’t get the correct response.

    Appreciate your help.

    Thank you,
    Fanny T


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 4.  RE: Pub.client:http with mutiform-data

    Posted Thu July 23, 2020 09:00 AM

    Hi Fanny,

    If you want to post the data to HTTP using pub.client:http then you don’t need pub.flow:transportinfo.

    Rather you create the form-data using services below and post the mimestream.

    pub.mime:createMimeData
    pub.mime:getEnvelopeStream
    pub.mime:addMimeHeader
    pub.mime:addBodyPart ( this should be repeated for each of your data one for PDF and other for JSON)

    Once mimeObject is ready you can post it to via pub.client:http service.

    Refer Integration_Server_Built_In_Services_Reference.pdf for more details

    Regards,
    Firoz N


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 5.  RE: Pub.client:http with mutiform-data

    Posted Sat July 25, 2020 10:16 AM

    Hi Firoz,

    Thanks for the step on forming MIMEData.
    I have created the service to load the JSON file first with following step:

    1. pub.mime:createMimeData
    2. pub.file:getFile ( get the json file and map to body=>stream)
    3. pub.mime:addMimeHeader (set the key as “thread_input”)

    1. pub.mime:addBodyPart (map body=>stream from no. 2 to content and set contentType to “application/json”)
    2. pub.mime:getEnvelopeStream
    3. pub.client:http ( map envStream to data=>mimeStream)

    But i still dont get the same result like using the POSTMAN.
    How do I add the key = “thread_input” in MIMEHeader?

    Seems it is not accepted by the WebService as i got response 415 not the expected 201 when i posted it from POSTMAN.

    Kindly advise.

    Thank you again,
    Fanny T


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 6.  RE: Pub.client:http with mutiform-data

    Posted Sun July 26, 2020 11:11 AM

    when you call: [quote=“Fanny_Sari1, post:5, topic:228929”]
    pub.mime:addMimeHeader
    [/quote]
    for pdf and json, make sure you have the Content-Type header populated.
    Is “key” a required header for your target system? header contains name/value pairs. “key” is normally not the name of the key.


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 7.  RE: Pub.client:http with mutiform-data

    Posted Sun July 26, 2020 11:53 AM

    Hi Wang Tong,

    I think the required one is “thread_input” for json file and “files” for the pdf like in the postman.
    I will try to give:
    *) thread_input = json filename.
    *) files = pdf filename.

    I will keep posted the result.
    Thank you.
    Fanny T


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 8.  RE: Pub.client:http with mutiform-data

    Posted Sun July 26, 2020 12:34 PM

    Hi Wang Tong,

    I have tried to put like following:
    MimeHeader
    *) thread_input = json file name.
    *) content-type= application/json.

    It still having the 415 result instead of 201.
    Looks like the Header format somehow is not accepted by target system.

    Appreciate any idea how to make this works?

    Thank you,
    Fanny T


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 9.  RE: Pub.client:http with mutiform-data

    Posted Mon July 27, 2020 09:41 AM

    Hi Fanny,

    Passing json file name as value is invalid. You should be passing the object data loaded from getFile service as value. preferable load as string in getFile service.

    In PostMan original request object is a file in json format and content-type is set as application\json.

    So in wM you try to create name/value pair as thread/input & json object(string from getFile) along with content-type as application\json.

    That way when you invoke the service won’t fail with invalid content-type.

    Current request you are making, you are passing thread-input as a string with value as filename i.e. json filename, that is wrong.

    Please check what actually required to pass then do pass accordingly.

    Let us know if our understanding of your requirement itself is wrong.

    Regards,
    Firoz N


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 10.  RE: Pub.client:http with mutiform-data

    Posted Mon July 27, 2020 12:32 PM

    Hi Firoz,

    If i understand correctly, i need to create in service addMimeHeader:
    *) thread_input = string from getFile
    *) content-type = application/json

    Please correct me if i am wrong.
    Since i still get the incorrect response from the URL (415 instead of 201).

    Actually the requirement for Body in POSTMAN need to be a file for thread_input and files. So i guess it is more like attachment?

    Thank you.

    Best Regards,
    Fanny T


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 11.  RE: Pub.client:http with mutiform-data

    Posted Mon July 27, 2020 12:56 PM

    Fanny,

    The content should be mapped in addBodyPart and not in addMimeHeader.

    Regards,
    Firoz N


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 12.  RE: Pub.client:http with mutiform-data

    Posted Tue July 28, 2020 03:18 AM

    Hi Firoz,

    I am sorry, could you be more specific? I am bit confuse now.
    Which one of the following step that i need to change?

    1. pub.mime:createMimeData
    2. pub.file:getFile ( get the json file and map to body=>stream)
    3. pub.mime:addMimeHeader
    4. pub.mime:addBodyPart (map body=>stream from no. 2 to content and set contentType to “application/json”)
    5. pub.mime:getEnvelopeStream
    6. pub.client:http ( map envStream to data=>mimeStream)

    Kindly advise.

    Thank you,
    Fanny T


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 13.  RE: Pub.client:http with mutiform-data

    Posted Tue July 28, 2020 11:00 AM

    Hi Fanny,

    This looks correct to me from the steps you listed above.

    I guess you need to check with vendor or host who is causing failure for this service and give more information.

    one thing you can try is to change the contentType to text/plain in addBodyPart. See if that works.

    Regards,
    Firoz N


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 14.  RE: Pub.client:http with mutiform-data

    Posted Thu July 30, 2020 04:24 AM

    Hi All,

    Finally I managed to solve the puzzle with help of good people. :slight_smile:

    Here are the step:

    • pub.mime:createMimeData
    • pub.io:stringToStream
    • pub.mime:addBodyPart
      (add string to mimeHeader, set name as “Content-Disposition” and value to “form-data; name=thread_input”)
      (set contenttype to “application/json”)
    • pub.mime:getEnvelopeStream
      (set createMultipart to “yes”)
    • Map mimeData=>Content-Type to headers=>Content-Type
    • pub.client:http
      (map envStream to data=>mimeStream)

    And I managed to get the correct response in partner URL.

    Thank you for Firoz and Wang Tong for your great help.
    Really appreciate it.

    Best Regards,
    Fanny T


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 15.  RE: Pub.client:http with mutiform-data

    Posted Wed August 12, 2020 06:36 PM

    Hi Fanny,

    I noticed that you did not mentioned about how you passing Files param (key/value) in the above logic in the mimeHeader??. Hope it was just a miss in the sudo logic description above?

    TIA,
    RMG


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 16.  RE: Pub.client:http with mutiform-data

    Posted Thu July 30, 2020 11:48 AM

    Hi Fanny,

    Glad to hear that the problem is solved. Appreciate sharing the solution as well. This will definitely help others a lot

    Regards,
    Firoz N


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 17.  RE: Pub.client:http with mutiform-data

    Posted Tue August 04, 2020 12:18 PM

    Thanks for sharing. Was looking to build similar to this, this gave me jump start.


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 18.  RE: Pub.client:http with mutiform-data

    Posted Tue August 04, 2020 12:37 PM

    Hi Jacob,

    Great to know. Please do share it here if you face any challenges or you enhance the solution for your functionality.

    Regards,
    Firoz N


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 19.  RE: Pub.client:http with mutiform-data

    Posted Mon November 23, 2020 11:19 AM

    HI ,

    I have the same scenario of sending a .txt file and and Json file as an attachment in REST API call.Basically wanted to replicate the below postman scenarion in http call in wM.


    I followed the similar steps by Fanny , But it is not working.Iam getting 400 Bad Request.

    Could any one please help and tell me if am missing something


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services