Aspose word cloud cURL how to mail merge, can't get it to work

Hi all,

I’m looking for a mail merge tool and came across Aspose Word Online to work with cURL’s.
Unfortunately the documentation isn’t very clear on how to work with different file locations.
I’m a beginner in programming so sorry in advance for things I might not get right away.

Here is the documentation regarding the mail merge but cant seem to get it to work.
I have the template and the data files stored locally but can’t get cURL to find the location,

This is my code and respond in git bash:

    $ curl -v "https://api.aspose.cloud/v4.0/words/MailMerge" \ -X PUT \ -F Template=@/Users/Niek Moor/source/SampleMailMergeTemplate.docx \ -F @/Users/Niek Moor/source/SampleMailMergeTemplateData.txt \ -H "Content-Type: multipart/form-data" \ -H "Accept: multipart/form-data" \ -H "Authorization: Bearer <eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE1OTk2NTM4NTQsImV4cCI6MTU5OTc0MDI1NCwiaXNzIjoiaHR0cHM6Ly9hcGkuYXNwb3NlLmNsb3VkIiwiYXVkIjpbImh0dHBzOi8vYXBpLmFzcG9zZS5jbG91ZC9yZXNvdXJjZXMiLCJhcGkucGxhdGZvcm0iLCJhcGkucHJvZHVjdHMiLCJhcGkuc3RvcmFnZSJdLCJjbGllbnRfaWQiOiJkZmU4ZDNmZi03ZDgzLTRlZjAtYjhhYi1mZGEyOTYzZTg3YWEiLCJjbGllbnRfZGVmYXVsdF9zdG9yYWdlIjoiNzY0NEQxNjEtQkIyQy00OUVDLTg5NjEtNzcxNkU2QjA1RkE2IiwiY2xpZW50X2lkU3J2SWQiOiI4MzUxOTQiLCJzY29wZSI6WyJhcGkucGxhdGZvcm0iLCJhcGkucHJvZHVjdHMiLCJhcGkuc3RvcmFnZSJdfQ.FBaItUYvrVZQGVqiRsS2UoMgYZun08ZQYGc35WCENSDCF5mWXFrFdq2TXCTS4k5SswZYzgLs9TaKKcZHwfyID0eAPMeQFYBzHn0vSxnn1XVIIkUL3DXOiACMW9z0hm1ARx9v08VH7jRef9sNhXZJ-dSafzJ25cD3dj4mh5beqm1fGsmz3g_CdXidtCRgJ4HczfKBZ2S9vOTa0ViC0qP2X1-MUry9oKtSwQXSNBZuBV0VIMzzY9gwj_KM02-g8MBcaP3peSiMCB9azECl1lxPXhaTJssW7Q68ZujJhM-MwZRC8pCVbRkzcP6kN-3A3n75XYsqVa2lR8y99Vd4sq9rLg>" \ -o TestPostDocumentExecuteMailMerge.docx
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 54.68.228.192:443...
* TCP_NODELAY set
* Connected to api.aspose.cloud (54.68.228.192) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
  CApath: none
} [5 bytes data]
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
* TLSv1.3 (IN), TLS handshake, Server hello (2):
{ [98 bytes data]
* TLSv1.2 (IN), TLS handshake, Certificate (11):
{ [4839 bytes data]
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
{ [333 bytes data]
* TLSv1.2 (IN), TLS handshake, Server finished (14):
{ [4 bytes data]
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
} [70 bytes data]
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
} [1 bytes data]
* TLSv1.2 (OUT), TLS handshake, Finished (20):
} [16 bytes data]
* TLSv1.2 (IN), TLS handshake, Finished (20):
{ [16 bytes data]
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
*  subject: CN=*.aspose.cloud
*  start date: Jan  1 00:00:00 2020 GMT
*  expire date: Feb  1 12:00:00 2021 GMT
*  subjectAltName: host "api.aspose.cloud" matched cert's "*.aspose.cloud"
*  issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon
*  SSL certificate verify ok.
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
} [5 bytes data]
* Using Stream ID: 1 (easy handle 0x25f25a0)
} [5 bytes data]
> GET /v4.0/words/MailMerge HTTP/2
> Host: api.aspose.cloud
> user-agent: curl/7.67.0
> accept: */*
>
{ [5 bytes data]
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
} [5 bytes data]
< HTTP/2 401
< date: Wed, 09 Sep 2020 12:20:24 GMT
< content-length: 0
< server: Kestrel
<
{ [0 bytes data]
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
* Connection #0 to host api.aspose.cloud left intact
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:12 --:--:--     0* Could not resolve host: PUT
* Closing connection 1
curl: (6) Could not resolve host: PUT
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Could not resolve host: @
* Closing connection 2
curl: (6) Could not resolve host: @
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:12 --:--:--     0* Could not resolve host: Moor
* Closing connection 3
curl: (6) Could not resolve host: Moor
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:13 --:--:--     0* Could not resolve host: C
* Closing connection 4
curl: (6) Could not resolve host: C
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:12 --:--:--     0* Could not resolve host: Moor
* Closing connection 5
curl: (6) Could not resolve host: Moor
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
* Closing connection -1
curl: (3) URL using bad/illegal format or missing URL
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:10 --:--:--     0* Could not resolve host: TestPostDocumentExecuteMailMerge.docx
* Closing connection 6
curl: (6) Could not resolve host: TestPostDocumentExecuteMailMerge.docx

I have no clue what i did wrong, and the aspose documentations doens’t explain anything on how to work the cURL example.

@niek.moor

Your cURL command is fine but it seems you are getting an issue because of the space in the path. Kindly enclose the path in double quotes as following, it should resolve the issue.

curl -X PUT "https://api.aspose.cloud/v4.0/words/MailMerge?withRegions=false&documentFileName=template" 
-H "accept: application/octet-stream" 
-H "Authorization: Bearer [Access_Token]" 
-H "Content-Type: multipart/form-data" -H "x-aspose-client: Containerize.Swagger" 
-F "Template=@C:/Temp/Mail Merge/SampleMailMergeTemplate.docx" 
-F "Data=@C:/Temp/Mail Merge/SampleMailMergeTemplateData.txt" 
--output C:/Temp/MailMergeOnline.docx

Thankyou very much for you reply!
For testing at the moment im using the curl commands in git bash.
The Double quotes didn’t help but i’ve moved the files to a location without a space and when using your example the command worked.
However right now I’m getting back an empty word document.
It does have the MailMergeOnline name but there is nothing inside.
Any idea what to do with that?

   curl -X PUT "https://api.aspose.cloud/v4.0/words/MailMerge?withRegions=false&documentFileName=template" 
   -H "accept: application/octet-stream" 
   -H "Authorization: Bearer [JWT-Token]" 
   -H "Content-Type: multipart/form-data" 
   -H "x-aspose-client: Containerize.Swagger" 
   -F "Template=@C:/Test/SampleMailMergeTemplate.docx" 
   -F "Data=@C:/Test/SampleMailMergeTemplateData.txt" 
   --output C:/Test/MailMergeOnline.docx

@niek.moor

I’m afraid the cURL command in git bash is working fine at my end. It is quite difficult to suggest anything without replicating the issue at my end. Can you please try the ExecuteMailMergeOnline API method using API explorer in your browser and share the results?

Hi, when i try that it seems to work but when i click on the download link it will download this strange file:
Screenshot_7.png (4.0 KB)

The first line of text is the name, then the date, and the “CLOUD_7E…” is the file format

And this is how the website looks after execute:
Screenshot_8.png (44.4 KB)

@niek.moor

It seems it is working fine, just rename the file to desired filename e.g. MailMerge_Output.docx. And the cURL command should work as well.

It doesn’t work for me:
Screenshot_9.png (17.5 KB)
Changed the output name but still 0 recieved
The new file is still an empty word document

@niek.moor

It is quite strange. Can you please confirm your git bash version and your OS details? We will try to replicate the issue at our end. Meanwhile, you may please try the API call in Postman?

Did file rename of download file to xxx.docx work for you?

Hi, my git bash its the newest version, so that will be 2.28.0 64-bit for windows 10
When trying with postman, I import the raw data and i’m getting status 401. Do i need to edit some things?
Screenshot_10.png (26.3 KB)

Futhermore when i change the download file to for example mailmerge.docx it works and the file is ok.
How is it possible that i need to do that? because it’s not that convenient to do that everytime.

@niek.moor

I’m using 2.25.1 64-bit for windows 10. I will double check with the latest version.

For passing authentication token in the postman, please use the authorization tab and to run API use Send and Download option instead of Send. Please check the following screenshots for details. Hopefully it will help you to test the API in the postman.

Hi, Using postman im able to get the merged file back so that seems to work!
Right now the response file is called ‘result’.
Is it possible to specify the outcome name like i was doing in cURL with git bash (which still doesn’t work), or does that normally work but just not in postman?
When making a call from my program i would like to save a file e.g. in a file server where i can specify the location and name of the file.
But i don’t know if both requirements are a problem or not.

@niek.moor

I have upgraded my git bash version to 2.28.0 and ExecuteMailMergeOnline API method is working as expected in it.

I doubt there is some issue with your JWT token used in the cURL command. Please run ExecuteMailMergeOnline API method in API Explorer, copy the cURL command from the API method, replace “-d {“Template”:{},“Data”:{}}” with “-F “Template=@C:/Test/SampleMailMergeTemplate.docx”
-F “Data=@C:/Test/SampleMailMergeTemplateData.txt”
–output C:/Test/MailMergeOnline.docx” and run it in the git bash. Hopefully it will resolve the issue.

@niek.moor

Can you please share some details? On which platform are you using Aspose.Words REST API? Because we have SDKs for different platforms to use Aspose.Words Cloud API directly in your programming language. We can share a working example with you.

Thanks! I manage to get the Git Bash command to work using this method!

1 Like

I’m not looking to work with the SDK, but with the API Call, the cURL method.
At the end i would like to select a template and data from my storage, probably an online database and send these 2 files with the call to your service. Then I would like to recieve the merged file and save it again in our database/server.
The program will be written in Java and from there we want to make the API call.

1 Like

@niek.moor

Good to know that you managed to cURL issue at your end. So it means you were getting the issue because of your expired token. Please note JWT Token has 24 hours lifetime and it expires after it. So if you are calling the API yourself via some rest client then you need to keep this in mind and regenerate the JWT token accordingly. However, we have taken care of this in Aspose Cloud SDKs.

curl -X POST "https://api.aspose.cloud/connect/token" 
-d "grant_type=client_credentials&client_id=[APP_SID]&client_secret=[APP_Key]" 
-H "Content-Type: application/x-www-form-urlencoded" 
-H "Accept: application/json"

Hi, I know about the token and that it can expire, but that wasn’t my problem.
I’ve compared the 2 cURL calls with each other and found out that i kept the <> markers in the call where the token is located. after removing them it worked :slight_smile:

1 Like

I don’t know if i’ts possible, but can you guys maybe give me a working example of making an API call in java? So not using the SDK but with the cURL method? Would be much appreciated!

@niek.moor

Sure, I will try to create a working sample and share with you asap.

Thankyou very much! i’m looking forward to your example :slight_smile:

1 Like