如何修复Convertapi中forapx合并在apex中的“状态=内部服务器错误,状态代码= 500”错误?

时间:2019-11-07 21:44:36

标签: json salesforce apex convertapi

我想使用“ 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 =内部服务器错误,StatusCode = 500”。

0 个答案:

没有答案