I cannot get either the API or Ruby SDK working when attempting to add comments to a word doc. I have tried using simple coordinates 0.0.0.0
and using the coordinates from a text search. For the Ruby SDK, I have used the nodes and document positions returned from the text search directly and built them with the SDK tooling. Regardless of what I do, I am getting this error message back: "Message\": \"Object reference not set to an instance of an object.
. Finding text and getting all comments work as expected.
This is the Ruby code I am using:
range_start = AsposeWordsCloud::DocumentPosition.new({ NodeId: node.range_start.node.node_id, Offset: node.range_start.offset })
range_end = AsposeWordsCloud::DocumentPosition.new({ NodeId: node.range_end.node.node_id, Offset: node.range_end.offset })
request_comment = AsposeWordsCloud::CommentInsert.new({
RangeStart: range_start,
RangeEnd: range_end,
Initial: 'IA',
Author: 'John Doe',
Text: 'A new Comment'
})
begin
Tempfile.create(['document', '.docx']) do |temp_file_2|
temp_file_2.binmode
temp_file_2.write(@document)
temp_file_2.rewind
insert_request = AsposeWordsCloud::InsertCommentOnlineRequest.new(document: @document, comment: request_comment)
@words_api.insert_comment_online(insert_request)
end
rescue StandardError => e
error_info = {
error: e.message,
class: e.class.name,
backtrace: e.backtrace&.take(1)
}
error_info[:response_body] = e.response_body if e.respond_to?(:response_body)
return { success: false, error: "Upload failed: #{error_info.inspect}", debug_info: @debug_info }
This is the version I attempted with the API call:
def get_aspose_token(client_id, client_secret)
response = HTTParty.post(
'https://api.aspose.cloud/connect/token',
body: {
grant_type: 'client_credentials',
client_id: client_id,
client_secret: client_secret
}
)
raise "Token error: #{response.body}" unless response.code == 200
JSON.parse(response.body)['access_token']
end
def add_comment_via_httparty(temp_file_path, node_id, offset, author, initials, text, token)
url = 'https://api.aspose.cloud/v4.0/words/online/post/comments'
comment = {
'RangeStart' => { 'Node' => { 'NodeId' => node_id }, 'Offset' => offset },
'RangeEnd' => { 'Node' => { 'NodeId' => node_id }, 'Offset' => offset },
'Author' => author,
'Initial' => initials,
'Text' => text
}
HTTParty.put(
url,
headers: { 'Authorization' => "Bearer #{token}" },
body: {
'document' => File.open(temp_file_path, 'rb'),
'comment' => comment.to_json
},
multipart: true
)
end