Document Generation Using .NET Core 3.1
This topic describes the details and sample code to merge the document with Salesforce data using .NET Core 3.1 SDK. You might use this functionality differently to generate documents depending on your business case.
See Composer REST APIs for a comprehensive list of Composer APIs that you can use for your business use case.
Prerequisites
The Composer APIs are available as part of an early adopter program that requires Conga product management review for inclusion.
- Contact your Account Executive with your 18-digit OrgID to enable the Composer API feature.
- Refer to the Authentication section to generate the Client ID and Client Secret that will be used in the code to connect to the Conga Authorization server.
- Refer to Step 2 to obtain the sessionId (Salesforce Access Token) that will be used to retrieve the Composer template and Salesforce data for the merge.
Document Generation
When you open the following sample .NET Core 3.1 class in a Visual Studio Console project, you can use the IDE to directly execute the 'Main' function in this class to initiate a Conga API merge.
In this sample code, we merge the document into PDF format and save it to Google Drive (You need to set up Google Drive under the Composer Setup Menu first). All the parameters are added to the LegacyOptions section of the Conga Ingress API call. For more information. see Step 3.
Sample Code (It may differ depending on your usage)
The Main function above assembles all four required API calls. The following is the description of each of these four API calls.
-
Conga Auth Access Token API call: In the sample code, the function that completed this task is called retrieveCongaAuthToken(). This API call returns the Conga-access-token, which will be used to authorize the Conga Ingress API call and the Conga Status-Service API call.
- HTTP Method: POST
- Server URL: https://services.congamerge.com/api/v1/auth/connect/token
- Required Headers: Content-Type: application/x-www-form-urlencoded
-
Post Body:
grant_type
‘client_credentials’
Scope
‘doc-gen.composer’
client_id
Retrieved from the Composer Setup Menu, and set in the code variable congaAuthClientId.
client_secret
Retrieved from the Composer Setup Menu, and set in the code variable congaAuthClientSecret.
-
Sample Response:
{ 'access_token': 'eyJh………… ', 'expires_in': 3600, 'token_type': 'Bearer', 'scope': 'doc-gen.composer' }
-
Salesforce Auth Access Token API call: In the sample code, the function that completed this task is called retrieveSalesforceAccessToken(). This API call returns the Salesforce-access-token, which will be used to authorize access to all the Salesforce data and Composer template stored in the Salesforce org.Note:
You can also retrieve the Salesforce Auth Access Token using any other way. More information can be found in the Salesforce documentation
- HTTP Method: POST
-
Server URL: - Sandbox:
https://test.salesforce.com/services/oauth2/token
- Production: https://login.salesforce.com/services/oauth2/token
-
Required Headers:- Content-Type: application/x-www-form-urlencoded
- Content-Length: String.valueOf(postBody.Length())
-
Post Body:
grant_type
‘password’
scope
‘doc-gen.composer’
client_id & client_secret
Create your own Salesforce connected app, get the Consumer Key and Consumer Secret, and set in the code variables salesforceConnectedAppClientId and salesforceConnectedAppClientSecret respectively.
username
‘{org user name}’
password
‘{org user password}’
-
Sample Response:
{ 'access_token': '………………', 'instance_url': 'https://speed-inspiration-509-dev-es.cs49.my.salesforce.com', 'id': 'https://test.salesforce.com/id/00D9A000000NlEbUAK/0058A000009SUwTQAW', 'token_type': 'Bearer', 'issued_at': '1649798597751', 'signature': '1p0VXuOaqgppeP8oMBOnQqhgwt6Fr6plKi8SaYkfMYo=' }
-
Composer merge process Ingress API call: In the sample code, the function that completed this task is called invokeCongaIngressApi(). This API call initiates the merge process and returns a correlationId that will be used in the next status-service call (see step 4).
- HTTP Method: POST
- Server URL: https://coreapps-rlsprod.congacloud.com/api/ingress/v1/Merge
-
Required Headers:- Content-Type: application/json- Content-Length: String.valueOf(postBody.Length())
- Authorization: Bearer + Conga Auth Access Token from the first Api call
-
Post Body:
{ 'SalesforceRequest': { 'sessionId': <Salesforce AccessToken from the second API call>, 'TemplateId':<set in the code variable composerTemplateId>, 'MasterId': <set in the code variable salesforceMasterObjId>, 'ServerUrl': <Salesforce serverUrl from the second API call> + ‘/services/Soap/u/50.0/’ + set in the code variable orgId } } 'LegacyOptions': {'DeFaultpdf':'1','Pdfa':'1a','DS7':'19','OFP':'<google-drive relative path>'} } For more information on supported parameters in the legacyOptions section for the Composer API request, click here.
-
Sample Response:
{ 'correlationId': '85c462d8ee494a96bdc9be9b5a87dd45_DatasetJson', 'status': 'Accepted', 'result': { 'statusCode': 'Success', 'statusMessage': [ { 'code': 'SUCC200', 'description': 'Success' } ] } }
-
Composer merge-status API call: In the sample code, the function that completed this task is called invokeCongaStatusServiceApi(). This API call checks the current merge's status and returns the status of all completed and ongoing merge steps. Call this API repeatedly until the response returns a message with the string "message":"Completed."
- HTTP Method: GET
- Server URL: https://services.congamerge.com/api/v1/status/v1/Status/ + { correlationId from the step 3 API call response}
-
Required Headers:
- Authorization: Bearer + Conga Auth Access Token from the first API call
-
Sample Response:
[ 'status': { 'version': '1.0.0', 'message': 'Pending', 'detail': 'Event publish request from Ingress', 'startDateTime': '2022-04-11T16:00:56.0204229Z', 'endDateTime': null, 'statusCode': 201 } ]