Clay Icon

Using Salesforce API to Create Email Objects for Account Activity

ยท
ยท

Hi team - is there a way to use the Salesforce API to create an email object in Salesforce (i.e. I push from Clay to Salesforce to record an email that has been sent that relates to a particular account and creates an object on the activity feed)?

  • Avatar of Channeled
    Channeled
    APP
    ยท
    ยท

    ๐Ÿ‘‹ Hey there! Our support team has got your message - we'll be back in touch soon. If you haven't already, please include the URL of your table in this thread so that we can help you as quickly as possible!

  • Avatar of Bo (.
    Bo (.
    ยท
    ยท

    Hey - You actually need to do this in 3 steps: 1. Authentication, Create email, Create relation, Create Task. If at any steps you're struggling, I'd use a LLM to troubleshoot this since they are very aware of what's required here. authentication: Method POST endpoint: https://login.salesforce.com/services/oauth2/token headers Content-Type: application/x-www-form-urlencoded body: { "grant_type": "password", "client_id": "YOUR_CLIENT_ID", "client_secret": "YOUR_CLIENT_SECRET", "username": "YOUR_USERNAME", "password": "YOUR_PASSWORD + SECURITY_TOKEN" } createEmail: Method: POST endpoint: https://YOURINSTANCE.salesforce.com/services/data/v59.0/sobjects/EmailMessage headers: Authorization: Bearer YOUR_ACCESS_TOKEN (The one from step 1) Content-Type: application/json body: { "Subject": "Email Subject", "TextBody": "Email Content", "ToAddress": "recipient@email.com", "FromAddress": "sender@email.com", "Status": "3", "MessageDate": "2025-01-07T12:00:00.000Z", "RelatedToId": "ACCOUNT_ID", "ActivityId": null } createRelation: method: POST endpoint: https://YOURINSTANCE.salesforce.com/services/data/v59.0/sobjects/EmailMessageRelation headers: Authorization: Bearer YOUR_ACCESS_TOKEN (The one from step 1) Content-Type: application/json body: { "EmailMessageId": "EMAIL_MESSAGE_ID", "RelationId": "ACCOUNT_ID", "RelationType": "ToAddress" } createTask: method: POST endpoint: https://YOURINSTANCE.salesforce.com/services/data/v59.0/sobjects/Task headers: Authorization: Bearer YOUR_ACCESS_TOKEN (The one from step 1) Content-Type: application/json "body": { "Subject": "Email: {Subject}", "Description": "Email sent to {recipient}", "Status": "Completed", "Priority": "Normal", "WhatId": "ACCOUNT_ID", "Type": "Email", "ActivityDate": "2025-01-07" } If you see any errorCodes "401": "Re-authenticate", "400": "Check payload format", "403": "Check API permissions", "404": "Verify Account ID exists" Make sure the API has all of those permissions as well: "API Enabled profile permission", "Create permission on EmailMessage object", "Create permission on EmailMessageRelation object", "Create permission on Task object (if creating tasks)" }

  • Avatar of Channeled
    Channeled
    APP
    ยท
    ยท

    This thread was picked up by our in-app web widget and will no longer sync to Slack. If you are the original poster, you can continue this conversation by logging into https://app.clay.com and clicking "Support" in the sidebar. If you're not the original poster and require help from support, please post in 02 Support.