Mail Merge in MS Word Document using Ruby on Rails Project

Hi,

I was going through the Aspose Word Cloud for Ruby language https://products.aspose.cloud/words/ruby/ and started incorporating it in my local project by adding the Ruby SDK but I guess I didn’t follow the necessary steps and was getting errors on multiple occasions.

Can you guide me with all the necessary steps in order to incorporate it in Ruby project? It would be a great favour.

Thanks.

@aliawan

Please double check that you have following the required steps. You can also check Aspose.Words Cloud SDK for Ruby usage details from GitHub.

Hopefully, it will help to integrate Aspose.Words Cloud in your Ruby project. However, if you still face any issues then please share the error details, we will guide you accordingly.

@tilal.ahmad

I added the Ruby SDK in my application and when I am configuring it with my ClientId and ClientSecret like this

    AsposeWordsCloud.configure do |config|
      config.client_data['ClientId'] = 'xxxxxxxxxxxxxxxx'
      config.client_data['ClientSecret'] = 'xxxxxxxxxxxxxxx'
    end

It gives me the following error
> ## undefined method client_data’ for #AsposeWordsCloud::Configuration:0x00007fec3d1cd910`

Whereas, if I change the above code with the following code then it works

AsposeWordsCloud.configure do |config|
      config.api_key['ClientId'] = 'xxxxxxxxxxxxxxxx'
      config.api_key['ClientSecret'] = 'xxxxxxxxxxxxxxxx'
    end

And after that lets suppose I want to populate data in merge fields via the code on this link https://docs.aspose.cloud/words/mail-merge/populate-with-data/. But then it give error on ExecuteMailMergeRequest that it is undefined class etc.

Help in all these regards will be highly appreciated. Thanks.

@aliawan

Please check the sample Mail Merge Ruby code. I installed Aspose.Words Cloud SDK for Ruby form rubygem.org and unable to notice any issue. Hopefully, it will help you to accomplish the task. You can check other unit tests from the GitHub repo for reference.

require 'aspose_words_cloud'

class Document

  include AsposeWordsCloud

  # Get Client ID and Client Secret from https://dashboard.aspose.cloud/
  Client_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxx"
  Client_ID = "xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx"
  FILE_PATH = "C:/Temp/"

  def initialize
    AsposeWordsCloud.configure do |config|
      config.client_data['ClientId'] = Client_ID
      config.client_data['ClientSecret'] = Client_KEY
	  end
    @words_api = WordsApi.new
  end

  # MailMerge
  def execute_mailmerge
      local_document_file = 'SampleMailMergeTemplate.docx'
      remote_file_name = 'SampleMailMergeTemplate.docx'
	  remote_file_output = 'TestExecuteTemplate.docx'
      local_data_file = File.read(FILE_PATH + 'SampleMailMergeTemplateData.txt')

      request_file_content = File.open(FILE_PATH+ local_document_file)
      request_upload = UploadFileRequest.new(file_content: request_file_content, path: remote_file_name)
      @words_api.upload_file(request_upload)

      request = ExecuteMailMergeRequest.new(name: remote_file_name, data: local_data_file, dest_file_name: remote_file_output)

      result = @words_api.execute_mail_merge(request)
end
end
	
	


document = Document.new()
puts document.execute_mailmerge

@tilal.ahmad

I have tried the above code you shared and now I am getting error this error
AsposeWordsCloud::ApiError: Bad Request
on the line
@words_api = WordsApi.new

I tried adding words_api gem as well but it didn’t resolve the error.

Help in this case will be highly appreciated. Thanks.

@aliawan

Please share your code screenshot along with the credentials via a private message. For a private message, please click on my user icon and opt the message tab with the required information. Kindly remove “RE:” from the title as well. We will investigate the issue and will update you.

@tilal.ahmad

Sent.

1 Like

@aliawan

It looks like your credentials issue. Please double check the credentials(Client Id and Secret) of your aspose.cloud application from aspose.cloud dashboard and confirm.

@tilal.ahmad

I just rechecked my credentials and I don’t know how the last character of my ClientId was missing.

Working now. Thank you.

1 Like