2

I'm trying to use the Ansible uri module to replicate the below curl statement, but I'm getting nowhere fast.

Is multipart/mixed supported, and if so how. Any thoughts?

curl "http://server_address" \
     -X POST \ 
     -H "Auth: blahblahblah" \ 
     -H "Content-Type: multipart/mixed;" \
     -F "request_payload=@pay_file.xml" \ 
     -F "workbook=@file.twb"
U880D
  • 8,601
  • 6
  • 24
  • 40
Stuart Milton
  • 63
  • 2
  • 6

1 Answers1

2

Your request actually seems contradictory, as pointed by the cURL documentation:

-F, --form <name=content>

(HTTP SMTP IMAP) For HTTP protocol family, this lets curl emulate a filled-in form in which a user has pressed the submit button. This causes curl to POST data using the Content-Type multipart/form-data according to RFC 2388.

Source: https://curl.se/docs/manpage.html#-F, emphasis mine

So I guess you don't really end up with a Content-Type: multipart/mixed.

So from what it seems here is what you are looking at:

- uri:
    url: http://example.org
    ## -X POST
    method: POST     
    ## -H "Auth: blahblahblah"                                  
    url_username: some_user
    url_password: some_password
    ## You might also need this one
    # force_basic_auth: true
    ## Content-type as forced by cURL when using -F
    body_format: form-multipart
    body:
      ## -F "request_payload=@pay_file.xml"
      request_payload: 
        content: "{{ lookup('file', 'pay_file.xml') }}"
        filename: pay_file.xml
        mime_type: application/xml
      ## -F "workbook=@file.twb"
      workbook: 
        content: "{{ lookup('file', 'file.twb') }}"
        filename: file.twb
        mime_type: application/twb

Also see:

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
  • Hi, thanks for your full response. I'm using the rest call provided by the 3rd party provider here - https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_get_started_tutorial_part_2.htm Will give this a blast and see if it plays ball. – Stuart Milton Dec 09 '20 at 13:34
  • 1
    You can verify, using eg. https://httpbin.org/, that the request from curl actually has Content-Type: multipart/mixed. I guess `-H` overrides the default from `-F`. – Michał Politowski Dec 10 '20 at 10:42
  • 1
    Thanks for pointing @MichałPolitowski, then I guess Ansible is enforcing this more strictly since their doc point at the fact that *The 'Content-Type' header cannot be overridden when using `form-multipart`* — https://docs.ansible.com/ansible/latest/collections/ansible/builtin/uri_module.html#parameter-body_format – β.εηοιτ.βε Dec 10 '20 at 10:45
  • @β.εηοιτ.βε did you find a solution ? I am having the exact same issue also with the Tableau API – John P Jul 23 '21 at 08:54