Highlighted
Respected Contributor.
Respected Contributor.
276 views

REST Driver - multipart/form-data Body in POST requests

Jump to solution

Hi all,

I need to connect a REST Driver with an API that uses multipart/form-data body content type for their POST REST actions.

I tried setting the corresponding header ( Content-type: multipart/form-data) and the corresponding body acording to HTTP specification:

 

 

 

--Driver-Boundary
Content-Disposition: form-data; name="data_type"
json
--Driver-Boundary
Content-Disposition: form-data; name="file"
[{"User":"rcano","Name":"Rodrigo","Email":"rcano@testing.com.tests","Surname":"Cano Alcaraz","Token":"rcano","LanguageCode":"EN","Department_1":"CP1","Active":"1","Consumer_1":"tablet","ConsumerRole_1":"Headquarters"}]
--Driver-Boundary--

 

 

 

 

So, the driver-operation-data before the submit is like:

 

 

 

[02/25/20 12:48:54.071]:DrvCatalogPlayer ST:            Submitting document to subscriber shim:
[02/25/20 12:48:54.071]:DrvCatalogPlayer ST:            
<nds dtdversion="4.0" ndsversion="8.x">
  <input>
    <driver-operation-data association="rcano" class-name="user" command="add" currentOp="CreateUser" event-id="0" src-dn="\IDM-DEV\data\users\rcano">
      <request>
        <url-token hash_tag="&amp;hash=dhtyjhsdrhdrtjhdrjudrjdjd" ssid_tag="ssid=sthsrhsrhsrjrstjrjhsrjrts"/>
        <header content-type="multipart/form-data; boundary=Driver-Boundary"/>
        <value>--Driver-Boundary
Content-Disposition: form-data; name="data_type"
json
--Driver-Boundary
Content-Disposition: form-data; name="file"
[{"User":"rcano","Name":"Rodrigo","Email":"rcano@testing.com.tests","Surname":"Cano Alcarazes","Token":"rcano","LanguageCode":"EN","Department_1":"CP1","Active":"1","Consumer_1":"tablet","ConsumerRole_1":"Headquarters"}]
--Driver-Boundary--</value>
      </request>
    </driver-operation-data>
  </input>
</nds>
[02/25/20 12:48:54.074]:DrvCatalogPlayer ST:            DrvCatalogPlayer: sub-execute
[02/25/20 12:48:54.075]:DrvCatalogPlayer ST:            DrvCatalogPlayer: addHandler
[02/25/20 12:48:54.075]:DrvCatalogPlayer ST:            DrvCatalogPlayer: addHandler: class-name == 'user'
[02/25/20 12:48:54.076]:DrvCatalogPlayer ST:            DrvCatalogPlayer: Add: preparing POST to http://blabla.bla/api.php/api/v1/user/setUsers?ssid=dhtyjhsdrhdrtjhdrjudrjdjd&hash=dhtyjhsdrhdrtjhdrjudrjdjd
[02/25/20 12:48:54.076]:DrvCatalogPlayer ST:            DrvCatalogPlayer: Resetting headers
[02/25/20 12:48:54.077]:DrvCatalogPlayer ST:            DrvCatalogPlayer: Setting the following HTTP request properties:
 Authorization: <content suppressed>
[02/25/20 12:48:54.077]:DrvCatalogPlayer ST:            DrvCatalogPlayer:  Content-type:multipart/form-data
[02/25/20 12:48:54.077]:DrvCatalogPlayer ST:            DrvCatalogPlayer: Did a HTTP POST with 373 bytes of data to http://blabla.bla/api.php/api/v1/user/setUsers?ssid=dhtyjhsdrhdrtjhdrjudrjdjd&hash=dhtyjhsdrhdrtjhdrjudrjdjd
[02/25/20 12:48:54.214]:DrvCatalogPlayer ST:            DrvCatalogPlayer: Response code and message: 400 Bad Request
[02/25/20 12:48:54.215]:DrvCatalogPlayer ST:            SubscriptionShim.execute() returned:
[02/25/20 12:48:54.215]:DrvCatalogPlayer ST:            
<nds dtdversion="3.0">
  <source>
    <product build="20180222_0635" version="1.0.0.2">Identity Manager REST Driver</product>
    <contact>NetIQ Corporation.</contact>
  </source>
  <output>
    <status event-id="0" level="error" type="driver-general">
      <driver-operation-data association="rcano" class-name="user" command="add" currentOp="CreateUser" dest-dn="\IDM-DEV\data\users\rcano" event-id="0" src-dn="\IDM-DEV\data\users\rcano">
        <response>
          <url-token hash_tag="&amp;hash=dhtyjhsdrhdrtjhdrjudrjdjd" ssid_tag="ssid=dhtyjhsdrhdrtjhdrjudrjdjd"/>
          <header content-type="multipart/form-data; boundary=Driver-Boundary"/>
          <value message="Bad Request" status="400">{"code":400,"message":"DATA_TYPE_NOT_VALID","data":""}</value>
        </response>
      </driver-operation-data>
    </status>
  </output>
</nds>

 

 

 

 

Performing the same operation manually with a REST client ( like Postmant or Insomnia) works fine.

Is it possible that the Rest Driver is only able to send a Body content in JSON type? Has anybody been in the same trouble?

Thank you in advance,
Rodrigo

Labels (1)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Respected Contributor.
Respected Contributor.

Found the problem!

For some reason that I don't understand, if you set a Custom header in the driver configuration like:

rcano_0-1582645918399.png

The driver will only take the value before the ';' to make the request obviating the boundary parameter!!

 

 

 

 

[02/25/20 16:29:31.931]:DrvCatalogPlayer ST:            DrvCatalogPlayer: Setting the following HTTP request properties:
 Authorization: <content suppressed>
[02/25/20 16:29:31.932]:DrvCatalogPlayer ST:            DrvCatalogPlayer:  Content-type:multipart/form-data
[02/25/20 16:29:31.932]:DrvCatalogPlayer ST:            DrvCatalogPlayer: Did a HTTP POST with 375 bytes of data to http://balbla.net/api.php/api/v1/user/setUsers?ssid=hzxthxhthxtjtxjfj&hash=hzxthxhthxtjtxjfj
[02/25/20 16:29:32.108]:DrvCatalogPlayer ST:            DrvCatalogPlayer: Response code and message: 400 Bad Request
[02/25/20 16:29:32.109]:DrvCatalogPlayer ST:            SubscriptionShim.execute() returned:
[02/25/20 16:29:32.109]:DrvCatalogPlayer ST:            
<nds dtdversion="3.0">
  <source>
    <product build="20180222_0635" version="1.0.0.2">Identity Manager REST Driver</product>
    <contact>NetIQ Corporation.</contact>
  </source>
  <output>
    <status event-id="0" level="error" type="driver-general">
      <driver-operation-data association="rcano" class-name="user" command="add" currentOp="CreateUser" dest-dn="\IDM-DEV\data\users\rcano" event-id="0" src-dn="\IDM-DEV\data\users\rcano">
        <response>
          <url-token hash_tag="&amp;hash=hzxthxhthxtjtxjfj" ssid_tag="ssid=hzxthxhthxtjtxjfj"/>
          <header content-type="multipart/form-data; boundary=Driver-Boundary"/>
          <value message="Bad Request" status="400">{"code":400,"message":"DATA_TYPE_NOT_VALID","data":""}</value>
        </response>
      </driver-operation-data>
    </status>
  </output>
</nds>

 

 

 

 

However, if you define the header through policies like:

rcano_2-1582646079605.png

That will work like a charm:

 

 

 

[02/25/20 16:42:46.719]:DrvCatalogPlayer ST:            DrvCatalogPlayer: Setting the following HTTP request properties:
 Authorization: <content suppressed>
[02/25/20 16:42:46.720]:DrvCatalogPlayer ST:            DrvCatalogPlayer:  content-type:multipart/form-data; boundary=Driver-Boundary
[02/25/20 16:42:46.720]:DrvCatalogPlayer ST:            DrvCatalogPlayer: Did a HTTP POST with 375 bytes of data to http://blabla.net/api.php/api/v1/user/setUsers?ssid=ryaeryaseryaseryeasy&hash=ryaeryaseryaseryeasy
[02/25/20 16:42:46.941]:DrvCatalogPlayer ST:            DrvCatalogPlayer: Response code and message: 200 OK
[02/25/20 16:42:46.949]:DrvCatalogPlayer ST:            SubscriptionShim.execute() returned:
[02/25/20 16:42:46.950]:DrvCatalogPlayer ST:            
<nds dtdversion="3.0">
  <source>
    <product build="20180222_0635" version="1.0.0.2">Identity Manager REST Driver</product>
    <contact>NetIQ Corporation.</contact>
  </source>
  <output>
    <status event-id="0" level="success" type="driver-general">S
      <driver-operation-data association="rcano" class-name="user" command="add" currentOp="CreateUser" dest-dn="\IDM-DEV\data\users\rcano" event-id="0" src-dn="\IDM-DEV\data\users\rcano">
        <response>
          <url-token hash_tag="&amp;hash=ryaeryaseryaseryeasy" ssid_tag="ssid=ryaeryaseryaseryeasy"/>
          <header content-type="multipart/form-data; boundary=Driver-Boundary"/>
          <value message="OK" status="200">{"code":200,"message":"DATA_OK","data":{"transaction_id":25855}}</value>
        </response>
      </driver-operation-data>
    </status>
  </output>
</nds>

 

 

 

And of course, the requests works now as expected.

Problem solved, I hope it works for everyone in the same situation.

Regards,
Rodrigo

 

 

 

 

View solution in original post

0 Likes
3 Replies
Highlighted
Respected Contributor.
Respected Contributor.

Found the problem!

For some reason that I don't understand, if you set a Custom header in the driver configuration like:

rcano_0-1582645918399.png

The driver will only take the value before the ';' to make the request obviating the boundary parameter!!

 

 

 

 

[02/25/20 16:29:31.931]:DrvCatalogPlayer ST:            DrvCatalogPlayer: Setting the following HTTP request properties:
 Authorization: <content suppressed>
[02/25/20 16:29:31.932]:DrvCatalogPlayer ST:            DrvCatalogPlayer:  Content-type:multipart/form-data
[02/25/20 16:29:31.932]:DrvCatalogPlayer ST:            DrvCatalogPlayer: Did a HTTP POST with 375 bytes of data to http://balbla.net/api.php/api/v1/user/setUsers?ssid=hzxthxhthxtjtxjfj&hash=hzxthxhthxtjtxjfj
[02/25/20 16:29:32.108]:DrvCatalogPlayer ST:            DrvCatalogPlayer: Response code and message: 400 Bad Request
[02/25/20 16:29:32.109]:DrvCatalogPlayer ST:            SubscriptionShim.execute() returned:
[02/25/20 16:29:32.109]:DrvCatalogPlayer ST:            
<nds dtdversion="3.0">
  <source>
    <product build="20180222_0635" version="1.0.0.2">Identity Manager REST Driver</product>
    <contact>NetIQ Corporation.</contact>
  </source>
  <output>
    <status event-id="0" level="error" type="driver-general">
      <driver-operation-data association="rcano" class-name="user" command="add" currentOp="CreateUser" dest-dn="\IDM-DEV\data\users\rcano" event-id="0" src-dn="\IDM-DEV\data\users\rcano">
        <response>
          <url-token hash_tag="&amp;hash=hzxthxhthxtjtxjfj" ssid_tag="ssid=hzxthxhthxtjtxjfj"/>
          <header content-type="multipart/form-data; boundary=Driver-Boundary"/>
          <value message="Bad Request" status="400">{"code":400,"message":"DATA_TYPE_NOT_VALID","data":""}</value>
        </response>
      </driver-operation-data>
    </status>
  </output>
</nds>

 

 

 

 

However, if you define the header through policies like:

rcano_2-1582646079605.png

That will work like a charm:

 

 

 

[02/25/20 16:42:46.719]:DrvCatalogPlayer ST:            DrvCatalogPlayer: Setting the following HTTP request properties:
 Authorization: <content suppressed>
[02/25/20 16:42:46.720]:DrvCatalogPlayer ST:            DrvCatalogPlayer:  content-type:multipart/form-data; boundary=Driver-Boundary
[02/25/20 16:42:46.720]:DrvCatalogPlayer ST:            DrvCatalogPlayer: Did a HTTP POST with 375 bytes of data to http://blabla.net/api.php/api/v1/user/setUsers?ssid=ryaeryaseryaseryeasy&hash=ryaeryaseryaseryeasy
[02/25/20 16:42:46.941]:DrvCatalogPlayer ST:            DrvCatalogPlayer: Response code and message: 200 OK
[02/25/20 16:42:46.949]:DrvCatalogPlayer ST:            SubscriptionShim.execute() returned:
[02/25/20 16:42:46.950]:DrvCatalogPlayer ST:            
<nds dtdversion="3.0">
  <source>
    <product build="20180222_0635" version="1.0.0.2">Identity Manager REST Driver</product>
    <contact>NetIQ Corporation.</contact>
  </source>
  <output>
    <status event-id="0" level="success" type="driver-general">S
      <driver-operation-data association="rcano" class-name="user" command="add" currentOp="CreateUser" dest-dn="\IDM-DEV\data\users\rcano" event-id="0" src-dn="\IDM-DEV\data\users\rcano">
        <response>
          <url-token hash_tag="&amp;hash=ryaeryaseryaseryeasy" ssid_tag="ssid=ryaeryaseryaseryeasy"/>
          <header content-type="multipart/form-data; boundary=Driver-Boundary"/>
          <value message="OK" status="200">{"code":200,"message":"DATA_OK","data":{"transaction_id":25855}}</value>
        </response>
      </driver-operation-data>
    </status>
  </output>
</nds>

 

 

 

And of course, the requests works now as expected.

Problem solved, I hope it works for everyone in the same situation.

Regards,
Rodrigo

 

 

 

 

View solution in original post

0 Likes
Highlighted
Knowledge Partner
Knowledge Partner

Now that is an interesting issue. Glad you figured it out.  Have to ask, what made you think about looking it that particular aspect of it?

0 Likes
Highlighted
Respected Contributor.
Respected Contributor.
Usually I define the headers in the driver configuration if its possible, but In this particular case, searching differences between a manual execution and the driver execution I noticed that the shim was not sending the full header information, so I tried to set it through policies as I did in other projects before and it just worked as expected.

In fact, I'm remembering other particular case where I need to specify the "charset" in the "Content-type" header ( application/json; charset=UTF-8) , and the solution was the same as here 🙂
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.