Robotic Process Automation (RPA)

 View Only

How do you send a file and parameters in Http request with multipart form data?

  • 1.  How do you send a file and parameters in Http request with multipart form data?

    Posted Mon April 10, 2023 03:42 PM

    I'm able to pass a request using Postman.  What I'd like to do is transcribe the postman calls into IBM RPA.  Any assistance would be helpful.  The error response I'm getting is a general 400 error stating the request failed "ObjectStoreId:null"

    IBM RPA
    defVar --name success --type Boolean
    defVar --name objectStoreId --type HttpContent
    defVar --name content --type HttpContent
    defVar --name responseHeader --type StringDictionary --innertype String
    defVar --name multicontentvar --type HttpContent
    defVar --name response --type String
    defVar --name statusCode --type Numeric
    defVar --name multipart --type HttpContent
    defVar --name fileContent --type HttpContent
    defVar --name authVariable --type StringDictionary --innertype String
    strDictAdd --key Authorization --value "Basic cDhhZG1pbjpsaGMkbzcxMw==" --dictionary ${authVariable}
    createHttpContent --formattype "Bytes" --file "C:/Accord/AcordMitch.pdf" fileContent=value
    createHttpContent --formattype "Multipart" --contentlist "{\"file\":\"${fileContent}\"}" multipart=value
    createHttpContent --formattype "Json" --body "{\"objectStoreId\": \"{F94CF4D3-8FA7-43D6-8FCD-3C687E914766}\"}\n  " objectStoreId=value
    createHttpContent --formattype "Multipart" --contentlist "objectstore=${objectStoreId}" content=value
    createHttpContent --formattype "Multipart" --boundary asdfasf --contentlist "content1=${content}, content2=${multipart}" multicontentvar=value
    httpRequest --verb "Post" --url "https://ec2-34-195-27-187.compute-1.amazonaws.com:9443/integrator/rest/docs" --headers ${authVariable} --formatter "Instance" --source "${multicontentvar}" success=success response=value statusCode=statusCode responseHeader=headers
    logMessage --message "Sucess: ${success}\r\nResponse: ${response}\r\nStatus Code: ${statusCode}\r\nResponse Header: ${responseHeader}" --type "Info"

    Postman (this works)



    ------------------------------
    John Bourdeau
    ------------------------------