In a Joomla application I am getting a user info as follows and then I need to save the user info as a contact in a Dynamics 365 database through their REST API.
$user = JFactory::getUser();
$username = $user->username;
$name = $user->name;
I have looked up Dynamics documents around Web API and REST API like this and this, but none of them provide useful info how I can call the API to add a new contact. Currently, I am connecting to Dynamics 365 web application via this url: http://example.com:8088/mysite/api/data/v8.2. The linked post also talks about REST API, but only querying. I'm looking for a way to post data to Dynamics CRM using REST API.
First, open Visual Studio and Create a new solution and project. Secondly, right click on the project, and select Add>New Item. Thirdly, select Dynamics 365 Items, on the left, and then select 'Runnable Class (Job)' from the list. Fourthly, enter in a name.
The payload to create Contact using crm webapi will look like this: Read more
POST [Organization URI]/api/data/v8.2/contacts HTTP/1.1
Content-Type: application/json; charset=utf-8
OData-MaxVersion: 4.0
OData-Version: 4.0
Accept: application/json
{
"firstname": "Arun",
"lastname": "Vinoth"
}
Sorry am not from PHP background, but this link may help you.
Update:
I browsed little bit. Found the below code sample from SO answer. Update the [Organization URI]
with CRM URL, for ex. https://testorg.crm.dynamics.com
$url = '[Organization URI]/api/data/v8.2/contacts';
$data = array('firstname' => 'Arun', 'lastname' => 'Vinoth');
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With