Parth Trivedi
Parth Trivedi

Reputation: 3832

POST Email Using Web API not reflecting "sender" and "torecipients" data

I want to create Email using MS Dynamics Web API.

Here I am posting data

{
  "sender": "[email protected]",
  "torecipients": "[email protected]",
  "subject": "Test Subject New 1234567",
  "description": "Test Description New 1234567"
}

But sender and torecipients are not reflecting in Dynamics CRM. Only subject & description are displaying.

Is there anything I am missing?

Upvotes: 2

Views: 798

Answers (2)

surya deepak
surya deepak

Reputation: 13

with this approach From vales are getting populated but CC and To vales are not getting populated.

Using this function with dataframe a input.

def transform_df(df):
        result = []
        for index, row in df.iterrows():  
            entity_binding = f"/{row['partyid_entitytype']}s({row['partyid'].upper()})"
            if row['participationtypemask'] == 1:
                if row['partyid_entitytype'] == '':
                    result.append({
                        f"addressused": f"{row['addressused']}",
                        "participationtypemask": row['participationtypemask']
                                    })
                else:
                    result.append({
                    f"partyid_{row['partyid_entitytype']}@odata.bind": f"{row['addressused']}",
                    "participationtypemask": row['participationtypemask']
                                    })
            elif row['participationtypemask'] == 2:
                if row['partyid_entitytype'] == '':
                    result.append({
                        f"addressused": f"{row['addressused']}",
                        "participationtypemask": row['participationtypemask']
                                    })
                else:
                    result.append({
                    f"partyid_{row['partyid_entitytype']}@odata.bind": entity_binding,
                    "participationtypemask": row['participationtypemask']
                                    })
            elif row['participationtypemask'] == 3:
                result.append({
                    f"addressused": f"{row['addressused']}",
                    "participationtypemask": row['participationtypemask']
                })
            elif row['participationtypemask'] == 4:
                result.append({
                    f"addressused": f"{row['addressused']}",
                    "participationtypemask": row['participationtypemask']
                })
        return result

Upvotes: 0

You have to populate collection valued navigation property email_activity_parties for filling up From & To fields. sender & torecipients are fields just for reporting purpose with emailaddress of those activity parties.

    var email = {};
    email["subject"] = "Email demo from Web API";
    email["description"] = "This a web api test";
    email["[email protected]"] = "/contacts(C41CE33F-D0A0-E611-811E-5065F38C8781)";

    //activityparty collection
    var activityparties = [];
    //from party
    var from = {};
    from["[email protected]"] = "/systemusers(8D23B2C1-9869-4C3F-9A80-BA51375C1784)";
    from["participationtypemask"] = 1;

    //to party
    var to = {};
    to["[email protected]"] = "/contacts(C41CE33F-D0A0-E611-811E-5065F38C8781)";
    to["participationtypemask"] = 2;

    activityparties.push(to);
    activityparties.push(from);

    //set to and from to email
    email["email_activity_parties"] = activityparties;

Read more

Edit:

JSON will look like this:

{
  "subject": "Test Subject New 1234567",
  "description": "Test Description New 1234567",
  "[email protected]": "/contacts(<GUID>)",
  "email_activity_parties": [
    {
      "[email protected]": "/contacts(<GUID>)",
      "participationtypemask": 2
    },
    {
      "[email protected]": "/systemusers(<GUID>)",
      "participationtypemask": 1
    }
  ]
}

Upvotes: 3

Related Questions