HTTP Post Request Attachment Error

I am using the http request activity. After trying to attach a file I got the following error when I try to preview the result. It does not matter what the name of the attachment is as I get the same error with the corresponding name. However, if I try previewing without an attachment I get a response meaning that the issue has to be with the way I am putting in the attachment.

)

Hi @NischalV,
Please check this:

Especially this part:

Important!
In some cases, an error might be returned stating that duplicate parameters cannot exist. These may be caused by authentication requests that need to contain the Password and Username parameters. In these cases, we recommend passing them using the Body property.

I think this might be related to your issue :slight_smile:

How would I pass it through the body property? Is there a specific format?

You type a string into the “Body” property of the activity. Note that for some reason the wizard does not show the body portion anywhere. You have to just edit it within the workflow itself. The format is generally either xml or json format, but could be anything depending on the website or service

########### Python Form Recognizer Analyze #############
from requests import post as http_post

# Endpoint URL
base_url = r"<Endpoint>" + "/formrecognizer/v1.0-preview/custom"
file_path = r"<path to your form>"
model_id = "<modelID>"
headers = {
    # Request headers
    'Content-Type': '<file type>',
    'Ocp-Apim-Subscription-Key': '<subscription key>',
}

try:
    url = base_url + "/models/" + model_id + "/analyze" 
    with open(file_path, "rb") as f:
        data_bytes = f.read()  
    resp = http_post(url = url, data = data_bytes, headers = headers)
    print("Response status code: %d" % resp.status_code)    
    print("Response body:\n%s" % resp.json())   
except Exception as e:
    print(str(e))

This is the code that I am trying to convert into the http request. Right now I can’t seem to figure out how exactly to attach the pdf file. When passed through the attachments feature in the wizard I get the error provided above. I tried adding the file path through the body property but that did not work either. I’m not sure if its related to the format that the uipath http request sends the file or what. If anyone has any ideas they would be greatly appreciated.

I’m not quite able to follow. However, for the http request you need a few things - i’ll lay it out from the http request properties.

Inputs:
AcceptFormat - Choose either XML or JSON (this is what format the website you’re working with requires)
EndPoint - this is the URL, self explanatory
Method - Post, self explanatory

Options:
Body - This is where you put in the payload. Depending on the AcceptFormat you chose above, it should be in either XML or JSON format. Check and double check the API to ensure your format is correct, this is where most of the info is usually sent.
BodyFormat - Usually application/xml (for XML formats) or application/json (for JSON formats) - check with your API for the bodyformat required
Cookies/Headers/Paramaters/UrlSegments - these are for parameterizing your request. 95%+ of the time I do not use them and just include everything in the body
ResourcePath - if you return a resource, this is the full filepath (including extension) of where you want the file to be saved

Output:
All 3 of these are fairly self explanatory. This is the response you get from your request. Results are in xml or json format depending on the website/service (check your api). StatusCode is an integer. Headers are returned in a dictionary (of type string, string)

If anyone has any experience using microsofts form recognizer service within uipath please let me know how you were able to do it. Also is there a specific way that uipath formats the attachments when sending them in the htttp request?

Hi

Has anyone figured out how to send an attachment in the http request activity while using it for a post request.

I could see above it has been mentioned that it can be sent in the body, but is there a sample request some one can attach

Hello can anyone help me for the same?

i am uploading the document and while accessing it is showing corrupted.
Please help me how to pass the parameters through Body.

It would be the great help. Please as it is urgent.

Thanks