Reputation: 2519
I am using PHP to connect to a Dynamics 2011 IFD and successfully authenticating and retrieving contacts to my web application.
I am however struggling to update a contact.
My SOAP request (below) is returning 'Bad Request' and unfortunately I do not have sufficient admin access to the server to enable more useful error reporting. Can anyone spot anything obvious in this XML which may be the issue?
$request = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
'.$this->crmAuth->GetSoapHeaderOnPremise("Update").'
<s:Body>
<Update xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<entity xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
<a:Attributes xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
<a:KeyValuePairOfstringanyType>
<b:key>contactid</b:key>
<b:value i:type="c:guid" xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/">'.$contactid.'</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>firstname</b:key>
<b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">'.$firstname.'</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>lastname</b:key>
<b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">'.$lastname.'</b:value>
</a:KeyValuePairOfstringanyType>
</a:Attributes>
<a:EntityState i:nil="true" />
<a:FormattedValues xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
<a:Id>'.$contactid.'</a:Id>
<a:LogicalName>contact</a:LogicalName>
<a:RelatedEntities xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
</entity>
</Update>
</s:Body>
</s:Envelope>'
The 'getSoapHeaderOnPremise' function is returning working auth headers for the retrieve/retrieveMultiple requests. The only difference here being the Update method being specified:
<a:Action s:mustUnderstand="1">http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Update</a:Action>
Upvotes: 1
Views: 132
Reputation: 1470
Never used it, but it looks like there is a project on Git to deal with this.
Upvotes: 0
Reputation: 17562
This is a wild guess, not having performed an update like this myself.
Remove this bit,
<a:KeyValuePairOfstringanyType>
<b:key>contactid</b:key>
<b:value i:type="c:guid" xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/">'.$contactid.'</b:value>
</a:KeyValuePairOfstringanyType>
This suggests you are trying set the record id field, which isn't something you normally do.
You have this bit which would seem to associate your update to a single record, so I suspect the above is not required.
<a:Id>'.$contactid.'</a:Id>
Upvotes: 1