Creating a webMethods.io REST connector for Salesforce Composite Graph
Tags: restapi, salesforce, webmethods, integration
Published: 2023-06-07 09:36:45

---
title: Creating a webMethods.io REST connector for Salesforce Composite Graph
published: true
date: 2023-05-10 01:10:12 UTC
tags: restapi, salesforce, webmethods, integration
canonical_url: https://tech.forums.softwareag.com/t/creating-a-webmethods-io-rest-connector-for-salesforce-composite-graph/278421
---

 

_products versions - {webMethods.io Integration [10.16.0.0]}_


## Introduction

Salesforce provides a composite graph API that allows you to process multiple graphs in a single request. Each graph can contain several composite requests, and each composite request can have multiple Salesforce objects to process. For more details on the composite graph, please refer to this [link](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_graph_introduction.htm).

> Here is an example of a Composite Graph request:
> 
> 1. This request consists of two graphs.
> 2. The first graph contains a composite request to create an Account object, followed by the creation of a Contact and an Opportunity object, both referring to the newly created Account ID. This creates a relationship between the three objects.
> 3. The second graph contains a composite request to create an Account and a Contact. The Contact is attached to the newly created Account.

[![image](https://global.discourse-cdn.com/techcommunity/original/3X/a/9/a97f1cb5582f047f4c7d22a957f1d5844047fabb.png)](https://global.discourse-cdn.com/techcommunity/original/3X/a/9/a97f1cb5582f047f4c7d22a957f1d5844047fabb.png "image")

```
{
  "graphs": [
    {
      "graphId": "1",
      "compositeRequest": [
        {
          "url": "/services/data/v57.0/sobjects/Account/",
          "body": {
            "name": "Company ABC"
          },
          "method": "POST",
          "referenceId": "reference_id_account_1"
        },
        {
          "url": "/services/data/v57.0/sobjects/Contact/",
          "body": {
            "FirstName": "Tarak",
            "LastName": "Konar",
            "AccountId": "@{reference_id_account_1.id}"
          },
          "method": "POST",
          "referenceId": "reference_id_contact_1"
        },
        {
          "url": "/services/data/v57.0/sobjects/Opportunity/",
          "body": {
            "CloseDate": "2023-11-10",
            "StageName": "Prospecting",
            "Name": "Opportunity to implement Composite Graph",
            "AccountId": "@{reference_id_account_1.id}"
          },
          "method": "POST",
          "referenceId": "reference_id_opportunity_1"
        }
      ]
    },
    {
      "graphId": "2",
      "compositeRequest": [
        {
          "url": "/services/data/v57.0/sobjects/Account/",
          "body": {
            "name": "Company DEF"
          },
          "method": "POST",
          "referenceId": "reference_id_account_2"
        },
        {
          "url": "/services/data/v57.0/sobjects/Contact/",
          "body": {
            "FirstName": "Rajiv",
            "LastName": "Asher",
            "AccountId": "@{reference_id_account_2.id}"
          },
          "method": "POST",
          "referenceId": "reference_id_contact_2"
        }
      ]
    }
  ]
}
```

This article will guide you through the step-by-step process of creating the `webMethods.io` Integration REST API connector for Salesforce Composite Graph. We will then demonstrate how to use this reusable connector in a `webMethods.io` Integration flow service to call the Salesforce Composite Graph API.

## Pre-requisite

There are two main prerequisites that you need to fulfill in order to implement this.

### `webMethods.io` integration tenant access and basic knowledge

Firstly, you should have access to a `webMethods.io` Integration tenant and have a basic understanding of `webMethods.io` Integration. If you are a beginner and need guidance on how to get a free-forever tenant on `webMethods.io` and start learning from beginner to advanced, please refer to the knowledge [article](https://tech.forums.softwareag.com/t/getting-started-with-webmethods-io-a-beginners-guide/276051) first.

### Create an App in Salesforce and get all credentials for OAuth

Secondly, you should have access to Salesforce and be able to create an App to obtain a Client ID, Secret, and refresh token for OAuth 2.0.

## Steps to follow

### Create REST API connector in `webMethods.io` Integration

1. Log in to your `webMethods.io` Integration tenant, open your project and go to the connectors tab.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/7/e/7e0070ffba14792f3554c161855a7831b6bf848e_2_517x109.png)](https://global.discourse-cdn.com/techcommunity/original/3X/7/e/7e0070ffba14792f3554c161855a7831b6bf848e.png "image")

2.Left-hand side, you can see all the different types of connectors. [Predefined](https://docs.webmethods.io/integration/connectors/connector-bundle/predefined-con/#gsc.tab=0), [REST](https://docs.webmethods.io/integration/connectors/connector-bundle/custom-con/#co-rest_connectors), [SOAP](https://docs.webmethods.io/integration/connectors/connector-bundle/custom-con/#co-overview_soap_connector), [On-premises](https://docs.webmethods.io/integration/connectors/connector-bundle/custom-con/#co-on_premises_connectors), [Flat File](https://docs.webmethods.io/integration/connectors/connector-bundle/custom-con/#co-flatfile). Please go to REST connector as we will be creating a new REST connector to work with Salesforce composite graph.

![image](https://global.discourse-cdn.com/techcommunity/original/3X/6/4/643b6e4c1efd3bcb4de8ec787b626d515db1fac1.png)

3.Please click on “Add Connector” located at the top right corner.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/c/7/c77e40f51e2698b3a247c986847723695b48ec55_2_690x161.png)](https://global.discourse-cdn.com/techcommunity/original/3X/c/7/c77e40f51e2698b3a247c986847723695b48ec55.png "image")

4.Provide a name of the custom REST API connector, default endpoint URL, Description, Authentication type and select an icon for the connector ( it should be in png format).  
The default endpoint URL will be your Salesforce env URL (e.g- [https://curious-xxxxx-xxxym-dev-ed.my.salesforce.com/services/data/v57.0](https://curious-xxxxx-xxxym-dev-ed.my.salesforce.com/services/data/v57.0))  
As Salesforce composite graph APIs use Oauth, will select Oauth V2.0 here. Then click Next.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/6/e/6e3625526c5a65e38475dba301f64b5b07f44b27_2_690x410.png)](https://global.discourse-cdn.com/techcommunity/original/3X/6/e/6e3625526c5a65e38475dba301f64b5b07f44b27.png "image")

[![image](https://global.discourse-cdn.com/techcommunity/original/3X/a/7/a75a7df40b8823866d3377a72958c2ea4987661e.png)](https://global.discourse-cdn.com/techcommunity/original/3X/a/7/a75a7df40b8823866d3377a72958c2ea4987661e.png "image")

5.On the next screen, will add resources. For composite graph, all calls should go to /composite/graph. So will add resources with path /composite/graph. This path will add to the base URL. We will provide a base URL as input while creating an account to connect to a specific Salesforce instance.

Please click “Add resource” on the top right.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/8/a/8accff9512b5110a905ec81c8ff44dbbb6e74545_2_690x73.png)](https://global.discourse-cdn.com/techcommunity/original/3X/8/a/8accff9512b5110a905ec81c8ff44dbbb6e74545.png "image")

Then provide Name, path, any description, and what methods are allowed for this resource. As composite graph takes post request, will select method post

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/1/7/17b38dbec1e32353709119705953120f0a81df1a_2_690x373.png)](https://global.discourse-cdn.com/techcommunity/original/3X/1/7/17b38dbec1e32353709119705953120f0a81df1a.png "image")

6.On the next screen, will select request parameters, headers and body content format.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/5/a/5a556d94d47f56fbbe1510d28e63033eb5d677ad_2_690x308.png)](https://global.discourse-cdn.com/techcommunity/original/3X/5/a/5a556d94d47f56fbbe1510d28e63033eb5d677ad.png "image")

For body content, will create a structure based on the input of Composite Graph API. So will click on the + icon, which will open the editor to define the input content structure. It also gives the option to create the document type based on an XML or a JSON sample. I will use a JSON sample to create the input format structure. Click on Load JSON.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/2/3/233f85714663990add9657b1d40ee84fac0a90ce_2_690x211.png)](https://global.discourse-cdn.com/techcommunity/original/3X/2/3/233f85714663990add9657b1d40ee84fac0a90ce.png "image")

![image](https://global.discourse-cdn.com/techcommunity/original/3X/4/e/4ea761609e32845c7fd55fde03b3702dd4c390e3.png)

Then select the document type and array as No.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/0/2/02a64b7df469c795aa0005b2284851c5381d56c5_2_690x236.png)](https://global.discourse-cdn.com/techcommunity/original/3X/0/2/02a64b7df469c795aa0005b2284851c5381d56c5.png "image")

Similarly will create the successful response (200) structure and possible error code (400) and corresponding structure. We can add more codes based on possible values it may return.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/1/7/1725bad90ec4181d5f9d7032b00898350d8c2090_2_690x212.png)](https://global.discourse-cdn.com/techcommunity/original/3X/1/7/1725bad90ec4181d5f9d7032b00898350d8c2090.png "image")

7.Now the REST connector for Salesforce composite graph is ready. As the next step, you need to create an account and operations to use in your specific interface/integration. First, let’s create a new Account. For that please come back to the main page of REST connectors, select the new connector, and on the right side click on “New Account”.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/6/5/6597bf473f666571be2abcbd17341c6eab417f9f_2_690x61.png)](https://global.discourse-cdn.com/techcommunity/original/3X/6/5/6597bf473f666571be2abcbd17341c6eab417f9f.png "image")

As we selected Oauth 2.0, so while creating an account, we need to provide a base URL, consumer ID, secret, access token, refresh token, URL. You need to get these parameters from Salesforce. For other parameters in the account creation page, please keep the default. We can have multiple accounts for different Salesforce instances.

![image](https://global.discourse-cdn.com/techcommunity/original/3X/2/6/26c43a47d232079cf15a47ea9fd9caea09ffcbda.png)

![image](https://global.discourse-cdn.com/techcommunity/original/3X/8/7/87e41b3523688a6ea1d2f191fd99cf6d7469ac64.png)

8.Now will add operations for this connector. For that please come back again to the main page of REST connectors, select the new connector, and on the right side click on Operations.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/2/2/2249237a025bb7ab11875104a193bc5992435570_2_690x62.png)](https://global.discourse-cdn.com/techcommunity/original/3X/2/2/2249237a025bb7ab11875104a193bc5992435570.png "image")

On the next page click on New Operation.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/9/9/99a43126470727c6aa5bdd523358f65b47092508_2_690x55.png)](https://global.discourse-cdn.com/techcommunity/original/3X/9/9/99a43126470727c6aa5bdd523358f65b47092508.png "image")

Give the name of the operation and select the account created. When you will be using this operation in interfaces, you can select other accounts also based on your requirements.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/c/4/c4dfd14ad301a197ca09aa3849104f04886015fd_2_489x375.png)](https://global.discourse-cdn.com/techcommunity/original/3X/c/4/c4dfd14ad301a197ca09aa3849104f04886015fd.png "image")

Select the operation which we added as a resource earlier. Click on headers and select which headers fields are needed for this operation. For this one, we need only one header field, which is content-type.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/7/5/752eab43c4dc8b25ac1e0993c249dd3a93c63eb5_2_690x175.png)](https://global.discourse-cdn.com/techcommunity/original/3X/7/5/752eab43c4dc8b25ac1e0993c249dd3a93c63eb5.png "image")

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/0/8/08ed0c992a99594bc55c7b5a164f98586845802e_2_690x84.png)](https://global.discourse-cdn.com/techcommunity/original/3X/0/8/08ed0c992a99594bc55c7b5a164f98586845802e.png "image")

### Using this custom REST connector to call Salesforce composite graph API from interface code

Now this connector is ready to use for any interfaces for sending Composite graph request to Salesforce using Salesforce composite graph API.

9.Let’s now use this new REST connector in a flow service.  
Here is the simple flow service, which takes composite graph request as input and then calls the REST connector and gets the output response from Salesforce.  
As the body of the composite graph API request is a free format structure, it can take any input based on specific requirements. We need to do the required mapping to create the structure based on the Salesforce objects we want to send as part of the request.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/6/2/62720bd76b1e8def3a4656c16a7bded743998725_2_484x500.png)](https://global.discourse-cdn.com/techcommunity/original/3X/6/2/62720bd76b1e8def3a4656c16a7bded743998725.png "image")

When calling the connector from the flow service. Select the operation and account we already created. You can create new custom operations or new accounts also.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/f/b/fbf7586617bc70a1de67b12e9115bc0f77b2e695_2_690x115.png)](https://global.discourse-cdn.com/techcommunity/original/3X/f/b/fbf7586617bc70a1de67b12e9115bc0f77b2e695.png "image")

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/d/8/d85e05e9c1be1cbbf76449ca5f6a46bd7b5e5603_2_690x45.png)](https://global.discourse-cdn.com/techcommunity/original/3X/d/8/d85e05e9c1be1cbbf76449ca5f6a46bd7b5e5603.png "image")

I am passing the input mentioned as an example during the introduction section.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/b/4/b484f5d5bc58c2d95e478a68dc9ad2b64965fe40_2_384x500.png)](https://global.discourse-cdn.com/techcommunity/original/3X/b/4/b484f5d5bc58c2d95e478a68dc9ad2b64965fe40.png "image")

It returns the output from Salesforce as objects created successfully.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/1/e/1e531c1d9745e49059ca656371033d7384742917_2_436x500.png)](https://global.discourse-cdn.com/techcommunity/original/3X/1/e/1e531c1d9745e49059ca656371033d7384742917.png "image")

Here is the JSON format of the response received.

```
{
  "status": "200",
  "statusMessage": "OK",
  "responseBody": {
    "response": {
      "graphs": [
        {
          "graphId": "1",
          "graphResponse": {
            "compositeResponse": [
              {
                "body": {
                  "id": "0016g00002Tfh9jAAB",
                  "success": true,
                  "errors": []
                },
                "httpHeaders": {
                  "Location": "/services/data/v57.0/sobjects/Account/0016g00002Tfh9jAAB"
                },
                "httpStatusCode": 201,
                "referenceId": "reference_id_account_1"
              },
              {
                "body": {
                  "id": "0036g00002NiomUAAR",
                  "success": true,
                  "errors": []
                },
                "httpHeaders": {
                  "Location": "/services/data/v57.0/sobjects/Contact/0036g00002NiomUAAR"
                },
                "httpStatusCode": 201,
                "referenceId": "reference_id_contact_1"
              },
              {
                "body": {
                  "id": "0066g00003eFOLWAA4",
                  "success": true,
                  "errors": []
                },
                "httpHeaders": {
                  "Location": "/services/data/v57.0/sobjects/Opportunity/0066g00003eFOLWAA4"
                },
                "httpStatusCode": 201,
                "referenceId": "reference_id_opportunity_1"
              }
            ]
          },
          "isSuccessful": true
        },
        {
          "graphId": "2",
          "graphResponse": {
            "compositeResponse": [
              {
                "body": {
                  "id": "0016g00002Tfh9kAAB",
                  "success": true,
                  "errors": []
                },
                "httpHeaders": {
                  "Location": "/services/data/v57.0/sobjects/Account/0016g00002Tfh9kAAB"
                },
                "httpStatusCode": 201,
                "referenceId": "reference_id_account_2"
              },
              {
                "body": {
                  "id": "0036g00002NiomVAAR",
                  "success": true,
                  "errors": []
                },
                "httpHeaders": {
                  "Location": "/services/data/v57.0/sobjects/Contact/0036g00002NiomVAAR"
                },
                "httpStatusCode": 201,
                "referenceId": "reference_id_contact_2"
              }
            ]
          },
          "isSuccessful": true
        }
      ]
    }
  }
}
```

### Verifying Composite graph API call is successful from Salesforce

10.Verifying all objects created in Salesforce.

Both accounts were created.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/4/6/465a860d7ad09e2b5b1b591b02891814a5c16450_2_690x153.png)](https://global.discourse-cdn.com/techcommunity/original/3X/4/6/465a860d7ad09e2b5b1b591b02891814a5c16450.png "image")

Contacts created.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/e/3/e3374e1036b4e344d0d2acc1db075822ae302b4e_2_690x99.png)](https://global.discourse-cdn.com/techcommunity/original/3X/e/3/e3374e1036b4e344d0d2acc1db075822ae302b4e.png "image")

Contact and Opportunity linked to Account as per Graph1.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/d/a/dab12b8da359e4b78dbc51532c9cb73b63419a28_2_690x399.png)](https://global.discourse-cdn.com/techcommunity/original/3X/d/a/dab12b8da359e4b78dbc51532c9cb73b63419a28.png "image")

Second contact is associated with the second account as per Graph 2.

[![image](https://global.discourse-cdn.com/techcommunity/optimized/3X/2/5/252cb3fcc713cea191e8a3988cc16ab6b7aa062a_2_690x370.png)](https://global.discourse-cdn.com/techcommunity/original/3X/2/5/252cb3fcc713cea191e8a3988cc16ab6b7aa062a.png "image")

## Useful links | Relevant resources

1. REST connector - [Custom Connectors - webMethods.io Integration](https://docs.webmethods.io/integration/connectors/connector-bundle/custom-con/#co-rest_connectors)
2. You can also build any custom connector using Connector Builder - Node.js CLI- [Connector Builder - Node.js CLI - webMethods.io Integration](https://docs.webmethods.io/integration/developer_guide/connector_builder/#gsc.tab=0)
3. If you are new to` webMethods.io`, this article can provide you with a good starting point - [Getting Started with webMethods.io: A Beginner's Guide](https://tech.forums.softwareag.com/t/getting-started-with-webmethods-io-a-beginners-guide/276051)


[Read full topic](https://tech.forums.softwareag.com/t/creating-a-webmethods-io-rest-connector-for-salesforce-composite-graph/278421)