TutorialConnect Gravity Forms to Salesforce (Auto-Fill by Email) with GravityWP API Connector

This tutorial walks you through a Gravity Forms Salesforce integration that auto-fills entries by email securely, on submit, and without custom code. You’ll use GravityWP API Connector, OAuth 2.0 (Client Credentials), and a SOQL query to fetch First Name, Last Name, and Company from Salesforce.

What does Gravity Forms Salesforce integration tutorial delivers

Each submission checks Salesforce for a matching Lead by the submitted Email. If a record exists, the entry is enriched with First Name, Last Name, and Company from Salesforce. The lookup in this example runs on form submission. But with our API Connector for Gravity Forms it is also possible to prefill form fields with Salesforce data in real-time.

Gravity Forms Salesforce integration Requirements

  • WordPress with Gravity Forms
  • GravityWP – API Connector add-on
  • Salesforce admin access to create an External Client App
  • At least one Lead in Salesforce with a unique Email
  • The Salesforce instance domain visible in the browser when logged in (example used here): https://orgfarm-7be0a7e638-dev-ed.develop.my.salesforce.com

Part 1 – Salesforce: External Client App

In Setup → External Client App Manager, create (or open) an app for this integration (e.g., Gravity Forms Integration) and ensure it is Enabled. In OAuth settings, enable Client Credentials Flow and include the api scope so a server can request an access token without a user login.

Open Consumer Key and Secret. Salesforce labels them “Consumer,” but the connector uses these as Client ID and Client Secret.

Salesforce External Client App Manager showing the enabled Gravity Forms Integration app.
Salesforce External Client App Manager with the ‘Gravity Forms Integration’ app enabled starting – point for the OAuth2 Client Credentials setup.
Salesforce OAuth settings with Client Credentials Flow enabled and api scope selected.
OAuth settings for the integration app with Client Credentials Flow enabled and the api scope selected for secure server-to-server calls.
Location of Salesforce Consumer Key and Secret used as Client ID and Client Secret.
Where to access the Consumer Key (Client ID) and Consumer Secret for the Gravity Forms ↔ Salesforce connection

Part 2 – WordPress: create the API Connection

Go to Forms → Settings → API Connector → Add New API Connection and enter:

  • Base URL: https://orgfarm-7be0a7e638-dev-ed.develop.my.salesforce.com
    (Just the instance domain; the connector appends endpoints to this base.)
  • Authentication method: OAuth 2.0 (Client Credentials)
  • Client ID / Client Secret: paste the Salesforce Consumer Key/Secret
  • Token URL: https://orgfarm-7be0a7e638-dev-ed.develop.my.salesforce.com/services/oauth2/token

Save the connection.

GravityWP API Connection configured for Salesforce with Base URL, OAuth 2.0 Client Credentials, and Token URL.
GravityWP API Connector configured with the Salesforce Base URL and Token URL on the instance domain – foundation of this Gravity Forms Salesforce integration.

Part 3 – Build the Gravity Form

Create fields for First Name, Last Name, Company, and Email; mark Email as Required. Note the Email field’s ID (in this example, 5), which appears in merge tags like {Email:5}.

Gravity Forms Fields
Form Fields inside Gravity Forms that we set up

Part 4 – Create the API Connector feed (Salesforce lookup)

Open the form → Settings → API Connector → Add New Feed. Give it a clear name.

Request
Set Request Method to GET and set the Endpoint (relative to the Base URL) to:

/services/data/v61.0/query

This is Salesforce’s REST Query resource: services/data is the REST base path; v61.0 is the API version; query accepts SOQL and returns JSON.

See the Salesforce REST API docs

SOQL via q parameter
Add a Query String parameter with Key = q and paste:

SELECT+Id,FirstName,LastName,Company,Email,Status+FROM+Lead+WHERE+Email='{Email:5}'+ORDER+BY+CreatedDate+DESC+LIMIT+1
  • SELECT lists the exact fields required.
  • FROM Lead targets the Lead object.
  • WHERE Email = ‘{Email:5}’ inserts the submitted Email value from the form.
  • ORDER BY … LIMIT 1 ensures a single deterministic record if duplicates ever appear.

The connector URL-encodes the query automatically; no manual encoding is needed.

Map JSON → fields
Map the response paths to Gravity Forms fields:

  • First Namerecords/0/FirstName
  • Last Namerecords/0/LastName
  • Companyrecords/0/Company

Only mapped fields are written to the entry; unmapped fields will not auto-fill.

Trigger & debug
Set the feed to run On form submission and enable Store full response to capture the raw JSON for testing.

API Connector feed using GET on Salesforce REST Query endpoint /services/data/v61.0/query.
GET request to Salesforce’s REST Query endpoint: /services/data/v61.0/query – the endpoint that executes SOQL and returns JSON.
SOQL passed in the q parameter filtering by submitted Gravity Forms Email.
SOQL passed via q: filtering by {Email:5} to find the matching Lead, then returning First Name, Last Name, Company, Email, and Status.
Mapping Salesforce JSON fields to Gravity Forms fields via records/0 paths.
Mapping Salesforce JSON to Gravity Forms fields: records/0/FirstName, records/0/LastName, and records/0/Company fill the entry after submit.
Feed set to run on form submission with full JSON response stored for testing.
Feed set to run on form submission with ‘Store full response’ enabled for easy debugging of the Salesforce JSON payload.

Part 5 – Test

Submit the form using an Email that exists in Salesforce. Open the entries list and confirm that First Name, Last Name, and Company are populated from the returned JSON. If “Store full response” is enabled, review the JSON to verify the paths. Logs will show a fulfillment line (e.g., “Entry #… marked as fulfilled.”).

Showing an example lead in salesforce
Example data inside our salesforce that we want to auto populate in Gravity Forms
Gravity Forms preview with a Salesforce email entered prior to submission.
Form preview with a known Salesforce email – submitting triggers the lookup used in this Gravity Forms Salesforce integration.
Gravity Forms entries table showing fields populated from Salesforce and the stored JSON.
Entry shows First Name, Last Name, and Company populated from Salesforce; stored JSON confirms the successful SOQL query and mapping.
Log confirming the API Connector feed fulfilled the Gravity Forms entry.
Log confirms the API Connector feed ran: ‘Entry marked as fulfilled’- final verification that the integration executed on submit.

After testing, you’ll have a reliable Gravity Forms Salesforce integration that enriches entries with data from your organization.

Gravity Forms Salesforce integration Quick fixes

  • Nothing filled? Confirm the merge tag uses the correct field ID ({Email:5} in this example).
  • totalSize: 0 in JSON? No matching Lead for the submitted Email.
  • Specific field empty? Ensure it’s both selected in SELECT and mapped to a field.
  • Auth error? Verify Client ID/Secret, Token URL, app Enabled status, and Client Credentials Flow.

Format output with Advanced Merge Tags.

Optional extensions

  • Query Contact instead of Lead by changing FROM Lead to FROM Contact and updating mappings.
  • Add more fields by extending SELECT and mapping the new JSON paths.
  • If pre-submit auto-fill is desired, switch the feed trigger to run on Email field change (different UX, not covered here).

Copy blocks

Endpoint (relative to Base URL)

/services/data/v61.0/query

SOQL

SELECT+Id,FirstName,LastName,Company,Email,Status+FROM+Lead+WHERE+Email='{Email:5}'+ORDER+BY+CreatedDate+DESC+LIMIT+1

JSON paths

records/0/FirstName
records/0/LastName
records/0/Company

Our Premium Add-ons for Gravity Forms

Read more tutorials about

All tutorials