Skip to content

Commit

Permalink
Adds support for custom_field
Browse files Browse the repository at this point in the history
  • Loading branch information
vmesel committed Dec 18, 2023
1 parent a9a8de7 commit 34c1f78
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
11 changes: 10 additions & 1 deletion target_salesforce_v3/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ def http_headers(self) -> dict:
headers["User-Agent"] = self.config.get("user_agent")
return headers

def get_fields_for_object(self, object_type):
"""Check if Salesforce has an object type and fetches its fields."""
req = self.request_api("GET", endpoint="sobjects/")
for object in req.json().get("sobjects", []):
if object["name"] == object_type or object["label"] == object_type or object["labelPlural"] == object_type:
obj_req = self.request_api("GET", endpoint=f"sobjects/{object['name']}/describe").json()
return {f["name"]: f for f in obj_req.get("fields", [])}


def validate_response(self, response: requests.Response) -> None:
"""Validate HTTP response."""
if response.status_code in [429] or 500 <= response.status_code < 600:
Expand Down Expand Up @@ -307,7 +316,7 @@ def process_custom_fields(self, record) -> None:
if cf_name not in salesforce_custom_fields:
# If there's a custom field in the record that is not in Salesforce
# create it
self.add_custom_field(cf['name'],label = cf.get('label'))
self.add_custom_field(cf['name'], label = cf.get('label'))

return None

Expand Down
14 changes: 2 additions & 12 deletions target_salesforce_v3/sinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,7 @@ def reference_data(self):
response = response.json()["records"]
return [{k: v for k, v in r.items() if k in ["Id", "Name"]} for r in response]

def preprocess_record(self, record, context):

if isinstance(record.get("addresses"), str):
record["addresses"] = json.loads(record["addresses"])

if isinstance(record.get("phone_numbers"), str):
record["phone_numbers"] = json.loads(record.get("phone_numbers"))

if isinstance(record.get("campaigns"), str):
record["campaigns"] = json.loads(record.get("campaigns"))
def preprocess_record(self, record: dict, context: dict):

record = self.validate_input(record)

Expand Down Expand Up @@ -209,7 +200,6 @@ def upsert_record(self, record, context):
except Exception as e:
self.logger.exception(f"Could not PATCH to {url}: {e}")
if record:

try:
response = self.request_api("POST", request_data=record)
id = response.json().get("id")
Expand Down Expand Up @@ -242,7 +232,7 @@ def validate_response(self, response):
msg = self.response_error_message(response)
raise FatalAPIError(msg)

def assign_to_campaign(self, contact_id, campaigns):
def assign_to_campaign(self,contact_id,campaigns:list) -> None:
"""
This function recieves a contact_id and a list of campaigns and assigns the contact_id to each campaign
Expand Down

0 comments on commit 34c1f78

Please sign in to comment.