Use Case:
- A REST API will be defined to handle the files sent by clients called (Postman REST Client) as attachment.
- The files sent as attachment will be sent to Zoho Task Creation Endpoint in order to create task with Document.
Note: When i tried with postman directly by calling Zoho task Creation API, It creates task with Document.
Can anyone please let me know how to achieve this in API of WSO2 EI 6.1.1
Postman:
When i put log level="full" inside api,getting below log.
When i decode it via Online Tool which gives base64 decoded content like below.
API Code:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/uploadAttachment" name="AtatchmentAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property name="messageType" scope="axis2" type="STRING" value="multipart/form-data"/>
<!-- <log level="full"/> -->
<log level="custom">
<property name="========UploadAttachment" value=" API Called=========="/>
<property name="========AttachmentName===" expression="get-property('transport', 'filename')"/>
</log>
<property expression="get-property('registry','gov:/ZohoConfig/ZohoAppConfigFile.txt')" name="accessToken" scope="default" type="STRING"/>
<!-- <log level="full"/> -->
<payloadFactory media-type="xml">
<format>
<ns:binary xmlns:ns="http://ws.apache.org/commons/ns/payload">$1</ns:binary>
</format>
<args>
<arg evaluator="xml" expression="//*[local-name()='binary']/text()"/>
</args>
</payloadFactory>
<script language="js">
<![CDATA[
var binaryNode =
mc.getEnvelope().getBody().getFirstElement().getFirstOMChild();
binaryNode.setBinary(true);
]]>
</script>
<property name="attachment_base64" expression="$body"/>
<log level="custom">
<property name="====attachment_base64====" expression="$body"></property>
</log>
<payloadFactory description="Form Response Payload" media-type="json">
<format>{"uploaddoc":$1}</format>
<args>
<arg evaluator="xml" expression="$ctx:attachment_base64"/>
</args>
</payloadFactory>
<log level="custom">
<property name="====uploaddoc_Payload====" expression="$body"></property>
</log>
<!-- <log level="full"/> -->
<property name="transport.vfs.ReplyFileName" value="ZohoTestFile.txt" scope="transport"/>
<property name="transport.vfs.Streaming" value="true" scope="transport"/>
<property name="ClientApiNonBlocking" action="remove" scope="axis2"/>
<property name="messageType" scope="axis2" value="application/binary"/>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
<header expression="fn:concat('Bearer ', '1000.CCCCCCCCCC.XXXXXXXXXXXXXXXXXX')" name="Authorization" scope="transport"/>
<call>
<endpoint>
<address uri="https://projectsapi.zoho.com/restapi/portal/36249112/projects/685798000000976352/tasks/685798000011774999/attachments/"/>
</endpoint>
</call>
<log>
<property expression="json-eval($.)" name="==API Response======"/>
</log>
<!-- <payloadFactory description="Form Response Payload" media-type="json">
<format>{"recipients":"Regularrrrrrrrrrrrr"}</format>
<args/>
</payloadFactory>
<log>
<property expression="json-eval($.)" name="==Final- CampaignBuilder_JsonRequest_ForCreation======"/>
</log> -->
<respond/>
<!-- <property expression="String(//mediate/file/@filename)" name="filename" scope="default" type="STRING"/> -->
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
API Response:
{
"error": {
"code": 6831,
"message": "Input Parameter Missing"
}
}
Reason: need to pass attachment to the param called "uploaddoc" when calling Zoho API. here i don't know how to set attachment to that field
Wire Logs:
3:04:42,565] [] INFO - APIDeployer API named 'AtatchmentAPI' has been deployed from file : D:ServerSetup 6.1.1wso2ei-6.1.1wso2mpcarbonapps-12341602833682469Att
-CAR_1.0.0.carAtatchmentAPI_1.0.0AtatchmentAPI-1.0.0.xml
3:04:42,565] [] INFO - ApplicationManager Successfully Deployed Carbon Application : AttachmentUpload-CAR_1.0.0 {super-tenant}
3:05:04,362] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "POST /uploadAttachment HTTP/1.1[
][
]"
3:05:04,363] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "User-Agent: PostmanRuntime/7.26.5[
][
]"
3:05:04,363] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Accept: */*[
][
]"
3:05:04,363] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Postman-Token: 21c46ad2-19fc-46a6-aea8-8113ac70817e[
][
]"
3:05:04,363] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Host: localhost:8280[
][
]"
3:05:04,363] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Accept-Encoding: gzip, deflate, br[
][
]"
3:05:04,364] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Connection: keep-alive[
][
]"
3:05:04,364] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Content-Type: multipart/form-data; boundary=--------------------------623932778277436708655778[
][
]"
3:05:04,364] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Cookie: bf42f62d55=64dc75f94d2bd72d94493d263847c08c[
][
]"
3:05:04,364] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Content-Length: 376[
][
]"
3:05:04,365] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "[
][
]"
3:05:04,365] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "----------------------------623932778277436708655778[
][
]"
3:05:04,365] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Content-Disposition: form-data; name="uploaddoc"; filename="ZohoAttachment.txt"[
][
]"
3:05:04,365] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Content-Type: text/plain[
][
]"
3:05:04,366] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "[
][
]"
3:05:04,370] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Hi,[
][
]"
3:05:04,371] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "This is zoho Attachment task[
][
]"
3:05:04,371] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "----------------------------623932778277436708655778[
][
]"
3:05:04,371] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "Content-Disposition: form-data; name="name"[
][
]"
3:05:04,373] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "[
][
]"
3:05:04,373] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "TaskAttachment Demo[
][
]"
3:05:04,373] [] DEBUG - wire HTTP-Listener I/O dispatcher-2 >> "----------------------------623932778277436708655778--[
][
]"
3:05:04,373] [] INFO - LogMediator ========UploadAttachment = API Called==========, ========AttachmentName=== = null
3:05:04,398] [] INFO - LogMediator ====attachment_base64==== = <soapenv:Body xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><ns:binary xmlns:ns="http://ws.apa
ns/ns/payload">LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTYyMzkzMjc3ODI3NzQzNjcwODY1NTc3OA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJ1cGxvYWRkb2MiOyBmaWxlbmFtZT0iW
1lbnQudHh0Ig0KQ29udGVudC1UeXBlOiB0ZXh0L3BsYWluDQoNCkhpLA0KVGhpcyBpcyB6b2hvIEF0dGFjaG1lbnQgdGFzaw0KLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTYyMzkzMjc3ODI3NzQzNjcwODY1NTc3OA
EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJuYW1lIg0KDQpUYXNrQXR0YWNobWVudCBEZW1vDQotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tNjIzOTMyNzc4Mjc3NDM2NzA4NjU1Nzc4LS0NCg==</ns:binary
dy>
3:05:04,402] [] INFO - LogMediator ====uploaddoc_Payload==== = <soapenv:Body xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><uploaddoc xmlns="http://ws.apache
se">LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTYyMzkzMjc3ODI3NzQzNjcwODY1NTc3OA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJ1cGxvYWRkb2MiOyBmaWxlbmFtZT0iWm9ob0F0dGFj
g0KQ29udGVudC1UeXBlOiB0ZXh0L3BsYWluDQoNCkhpLA0KVGhpcyBpcyB6b2hvIEF0dGFjaG1lbnQgdGFzaw0KLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTYyMzkzMjc3ODI3NzQzNjcwODY1NTc3OA0KQ29udGVud
lvbjogZm9ybS1kYXRhOyBuYW1lPSJuYW1lIg0KDQpUYXNrQXR0YWNobWVudCBEZW1vDQotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tNjIzOTMyNzc4Mjc3NDM2NzA4NjU1Nzc4LS0NCg==</uploaddoc></soapenv:
3:05:05,124] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "POST /restapi/portal/36249008/projects/685798000009576352/tasks/685798000011774013/attachments/ HTTP/1.1[
3:05:05,126] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Authorization: Bearer 1000.9df1f22e7d16ba95f0553af9855d40b5.f81f2af95682c8b398d0bb4939190d10[
][
]"
3:05:05,127] [] DEBUG - wire HTTPS-Sender I/O dispatcher-4 << "Cookie: bf42f62d55=64dc75f94d2bd72d94493d263847c08c[
][
]"
3:05:05,127] [] DEBUG