Objective-C Dynamics CRM: Create a Phone Call

Back to Index

Creates a phone call record regarding the Fourth Coffee account (b6a19cdd-88df-e311-b8e5-6c3be5a8b200), regarding the "Faulty product catalog" incident (c49e62a8-90df-e311-9565-a45d36fc5fe8), from the system user Allie Bellew (832698d1-b86a-47b5-a9a3-0cc710eb22e4), to the contact Gabriele Cannata (57a0e5b9-88df-e311-b8e5-6c3be5a8b200). A successful response is indicated by a 204 response status code with no response body.

Documentation: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/phonecall?view=dynamics-ce-odata-9

CURL Command

curl -X POST https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/phonecalls \
  -H "Accept: application/json" \
  -H "Content-Type: application/json; charset=utf-8" \
  -H "OData-MaxVersion: 4.0"  \
  -H "OData-Version: 4.0" \
  -H "Authorization: Bearer DYNAMICS_CRM_ACCESS_TOKEN" \
  -d '{
    "subject": "Sample Phone Call 123",
    "phonenumber": "3125551920",
    "description": "Sample phone call created using the Chilkat Rest API",
    "scheduledend": "2018-04-29T11:56:21Z",
    "regardingobjectid_account@odata.bind": "/accounts(b6a19cdd-88df-e311-b8e5-6c3be5a8b200)",
    "actualdurationminutes": 25,
    "directioncode": true,
    "phonecall_activity_parties": [
        {   "partyid_systemuser@odata.bind": "/systemusers(832698d1-b86a-47b5-a9a3-0cc710eb22e4)",
            "participationtypemask": 1 },
        {   "partyid_contact@odata.bind": "/contacts(57a0e5b9-88df-e311-b8e5-6c3be5a8b200)",
            "participationtypemask": 2 },
        {   "partyid_incident@odata.bind": "/incidents(c49e62a8-90df-e311-9565-a45d36fc5fe8)",
            "participationtypemask": 8 }
    ]
}'

Objective-C Example

#import <CkoRest.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.h>

CkoRest *rest = [[CkoRest alloc] init];
BOOL success;

//  URL: https://my-dynamics-domain.api.crm.dynamics.com/api/data/v9.0/phonecalls
BOOL bTls = YES;
int port = 443;
BOOL bAutoReconnect = YES;
success = [rest Connect: @"my-dynamics-domain.api.crm.dynamics.com" port: [NSNumber numberWithInt: port] tls: bTls autoReconnect: bAutoReconnect];
if (success != YES) {
    NSLog(@"%@%d",@"ConnectFailReason: ",[rest.ConnectFailReason intValue]);
    NSLog(@"%@",rest.LastErrorText);
    return;
}

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"subject" value: @"Sample Phone Call 123"];
[json UpdateString: @"phonenumber" value: @"3125551920"];
[json UpdateString: @"description" value: @"Sample phone call created using the Chilkat Rest API"];
[json UpdateString: @"scheduledend" value: @"2018-04-29T11:56:21Z"];
[json UpdateString: @"\"regardingobjectid_account@odata.bind\"" value: @"/accounts(b6a19cdd-88df-e311-b8e5-6c3be5a8b200)"];
[json UpdateNumber: @"actualdurationminutes" numericStr: @"25"];
[json UpdateBool: @"directioncode" value: YES];
[json UpdateString: @"phonecall_activity_parties[0].\"partyid_systemuser@odata.bind\"" value: @"/systemusers(832698d1-b86a-47b5-a9a3-0cc710eb22e4)"];
[json UpdateNumber: @"phonecall_activity_parties[0].participationtypemask" numericStr: @"1"];
[json UpdateString: @"phonecall_activity_parties[1].\"partyid_contact@odata.bind\"" value: @"/contacts(57a0e5b9-88df-e311-b8e5-6c3be5a8b200)"];
[json UpdateNumber: @"phonecall_activity_parties[1].participationtypemask" numericStr: @"2"];
[json UpdateString: @"phonecall_activity_parties[2].\"partyid_incident@odata.bind\"" value: @"/incidents(c49e62a8-90df-e311-9565-a45d36fc5fe8)"];
[json UpdateNumber: @"phonecall_activity_parties[2].participationtypemask" numericStr: @"8"];

[rest AddHeader: @"Content-Type" value: @"application/json; charset=utf-8"];
[rest AddHeader: @"OData-Version" value: @"4.0"];
[rest AddHeader: @"Accept" value: @"application/json"];
[rest AddHeader: @"OData-MaxVersion" value: @"4.0"];
[rest AddHeader: @"Authorization" value: @"Bearer DYNAMICS_CRM_ACCESS_TOKEN"];

CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[json EmitSb: sbRequestBody];
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestSb: @"POST" uriPath: @"/api/data/v9.0/phonecalls" requestBody: sbRequestBody responseBody: sbResponseBody];
if (success != YES) {
    NSLog(@"%@",rest.LastErrorText);
    return;
}

int respStatusCode = [rest.ResponseStatusCode intValue];
if (respStatusCode >= 400) {
    NSLog(@"%@%d",@"Response Status Code = ",respStatusCode);
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",rest.ResponseHeader);
    NSLog(@"%@",@"Response Body:");
    NSLog(@"%@",[sbResponseBody GetAsString]);
    return;
}