REST API knowledge exchange
Post Reply
Alim
Novice
Posts: 5
Liked: never
Joined: Mar 11, 2012 5:49 am
Full Name: Mohammad Alim
Contact:

Format for POST request body

Post by Alim »

Hi All

I encountered an error trying to perform a POST command with a request body input as a String type,

<Error Message="Unable to deserialize XML body with root name 'Binary' and root namespace '' (for operation 'CreateObjectInJob' and contract ('IEnterpriseRestService', 'http://www.veeam.com/ent/v1.0')) using XmlSerializer.

Is there any specific format to be used to post the XML body? Can we just define the XML body as a string value and use it as input for the POST command? Will it work that way?

Can advise.

Thanks.

Regards
Alim.
Alim
Novice
Posts: 5
Liked: never
Joined: Mar 11, 2012 5:49 am
Full Name: Mohammad Alim
Contact:

Re: Format for POST request body

Post by Alim »

Additional info with regards to the above, i am trying to use VMware Orchestrator (vco) to automate adding the VM to the job.

Workflow script

var requestContent = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<CreateObjectInJobSpec xmlns=\"http://www.veeam.com/ent/v1.0\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" +
"<HierarchyObjRef>urn:VMware:VM:5a12aea1-e48f-4bc5-85cd-59a8444a4acf.vm-645</HierarchyObjRef>" +
"<HierarchyObjName>backupclient1</HierarchyObjName>" +
"<Order>0</Order>" +
"<GuestProcessingOptions>" +
"<AppAwareProcessingMode>RequireSuccess</AppAwareProcessingMode>" +
"<FileSystemIndexingMode>ExceptSpecifiedFolders</FileSystemIndexingMode>" +
"<IncludedIndexingFolders/>" +
"<ExcludedIndexingFolders>" +
"<Path>%windir%</Path>" +
"<Path>%ProgramFiles%</Path>" +
"<Path>%TEMP%</Path>" +
"</ExcludedIndexingFolders>" +
"<CredentialsId/>" +
"</GuestProcessingOptions>" +
"</CreateObjectInJobSpec>";

var requestType = "POST";
var operationUrl = ""/jobs/aae2a6b-d3af-4b0c-b5fc-6b9c45206eeb/includes"
var request = restHost.createRequest(requestType, operationUrl, requestContent);

Error message

2015-04-13 11:00:10.089] <?xml version="1.0" encoding="utf-8"?><Error Message="Unable to deserialize XML body with root name 'Binary' and root namespace '' (for operation 'CreateObjectInJob' and contract ('IEnterpriseRestService', 'http://www.veeam.com/ent/v1.0')) using XmlSerializer. Ensure that the type corresponding to the XML is added to the known types collection of the service." StatusCode="500" xmlns="http://www.veeam.com/ent/v1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instan ... age>Unable to deserialize XML body with root name 'Binary' and root namespace '' (for operation 'CreateObjectInJob' and contract ('IEnterpriseRestService', 'http://www.veeam.com/ent/v1.0')) using XmlSerializer. Ensure that the type corresponding to the XML is added to the known types collection of the service.</FirstChanceExceptionMessage><StackTrace>Veeam.Backup.Interaction.RestAPI.CRestAPICommunicationException: Unable to deserialize XML body with root name 'Binary' and root namespace '' (for operation 'CreateObjectInJob' and contract ('IEnterpriseRestService', 'http://www.veeam.com/ent/v1.0')) using XmlSerializer. Ensure that the type corresponding to the XML is added to the known types collection of the service. ---> System.Runtime.Serialization.SerializationException: Unable to deserialize XML body with root name 'Binary' and root namespace '' (for operation 'CreateObjectInJob' and contract ('IEnterpriseRestService', 'http://www.veeam.com/ent/v1.0')) using XmlSerializer. Ensure that the type corresponding to the XML is added to the known types collection of the service.&#xD;
at System.ServiceModel.Dispatcher.SingleBodyParameterMessageFormatter.ReadObject(Message message)&#xD;
at System.ServiceModel.Dispatcher.SingleBodyParameterMessageFormatter.DeserializeRequest(Message message, Object[] parameters)&#xD;
at System.ServiceModel.Dispatcher.UriTemplateDispatchFormatter.DeserializeRequest(Message message, Object[] parameters)&#xD;
at Veeam.Backup.Enterprise.RestAPIService.FormsPostDispatchMessageFormatter.DeserializeRequest(Message message, Object[] parameters)&#xD;
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc)&#xD;
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)&#xD;
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)&#xD;
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)&#xD;
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)&#xD;
--- End of inner exception stack trace ---</StackTrace></Error>
greenhoorn
Service Provider
Posts: 14
Liked: 1 time
Joined: Mar 20, 2015 3:45 pm
Full Name: Joel Neutzner
Location: Switzerland
Contact:

Re: Format for POST request body

Post by greenhoorn » 1 person likes this post

Did you specify the ContentType-header? Take a look at the "must-have"-headers here: http://helpcenter.veeam.com/backup/80/rest/
Alim
Novice
Posts: 5
Liked: never
Joined: Mar 11, 2012 5:49 am
Full Name: Mohammad Alim
Contact:

Re: Format for POST request body

Post by Alim »

Yes, the header has been specified as "Content-Type" and "application/xml".

Thanks.
Alim
Novice
Posts: 5
Liked: never
Joined: Mar 11, 2012 5:49 am
Full Name: Mohammad Alim
Contact:

Re: Format for POST request body

Post by Alim »

greenhoorn wrote:Did you specify the ContentType-header? Take a look at the "must-have"-headers here: http://helpcenter.veeam.com/backup/80/rest/
I used my own script to post the header instead of the built-in script, and it works now. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests