1

我想使用“convertapi”合并我在 Salesforce 组织中的 PDF。

我点击此链接:https ://www.convertapi.com/pdf-to-merge并使用 JSON 和顶点的参考代码申请。代码在下面提到。

    List<Id> relatedFilesIdsList = new List<Id>();
    for(ContentDocumentLink cdl : [SELECT ContentDocumentId 
                                   FROM ContentDocumentLink 
                                   WHERE LinkedEntityId = 'XXXXX']){
                                    relatedFilesIdsList.add(cdl.ContentDocumentId);   
                                 }

    //Select list of attachments that should be merged
    List<ContentVersion> selectedAttachmentsList = [SELECT Title,VersionData 
                                                    FROM ContentVersion
                                                    WHERE ContentDocumentId IN :relatedFilesIdsList];
JSONGenerator gen = JSON.createGenerator(true); 
    gen.writeStartObject(); 
        gen.writeFieldName('Parameters');
        gen.writeStartArray();
        gen.writeStartObject();
            gen.writeStringField('Name','Files');
            gen.writeFieldName('FileValues');
            gen.writeStartArray();
                gen.writeStartObject();
                    gen.writeStringField('Name',selectedAttachmentsList[0].Title);
                    gen.writeBlobField('Data',selectedAttachmentsList[0].VersionData);
                gen.writeEndObject();
                gen.writeStartObject();
                    gen.writeStringField('Name',selectedAttachmentsList[1].Title);
                    gen.writeBlobField('Data',selectedAttachmentsList[1].VersionData);
                gen.writeEndObject();
            gen.writeEndArray();
        gen.writeEndObject();
        gen.writeEndArray();
    gen.writeEndObject();

String jsonS = gen.getAsString();
//System.debug(jsonS);

HttpRequest req = new HttpRequest();
req.setEndpoint('https://v2.convertapi.com/convert/pdf/to/merge?Secret=xxxxx');
req.setMethod('POST');
req.setHeader('Content-Type', 'application/json');
req.setbody(jsonS);
Http http = new Http();
HTTPResponse response = http.send(req);
System.debug(response);

但我不知道由于某种原因我收到错误:“ Status=Internal Server Error, StatusCode=500 ”。

4

0 回答 0