cancel
Showing results for 
Search instead for 
Did you mean: 

How to post survey question response through odata

migsafa
Explorer
0 Kudos
606

Hello!

We are posting survey answers through odata into C4C Sales. We have the question type "Date interval" that arrives like this:

--batch
content-type: multipart/mixed; boundary=changeset_ed81b200-0a1a-445b-9f0f-9d4a5018ee1c
--changeset_ed81b200-0a1a-445b-9f0f-9d4a5018ee1c
content-type: application/http
content-transfer-encoding: binary
POST SurveyQuestionAnswersCollection HTTP/1.1
Content-Length: 631
Content-Type: application/atom+xml
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xml:base="https://xxxxxxxx.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi">
   <content type="application/xml">
      <m:properties>
         <d:ParentObjectID>0279AAC5D4C81EECA8FA1B1E40949A73</d:ParentObjectID>
         <d:QuestionUUID>0279AAC5D4C81EECA6E3E512DCAE6287</d:QuestionUUID>
         <d:QuestionAnswerOptionUUID>0279AAC5D4C81EECA6E3E512DCB06287</d:QuestionAnswerOptionUUID>
         <d:Date>2022-02-01T00:00:00</d:Date>
      </m:properties>
   </content>
</entry>
--changeset_ed81b200-0a1a-445b-9f0f-9d4a5018ee1c--
--batch
content-type: multipart/mixed; boundary=changeset_4780804c-d760-43fe-ab06-2ed20bd173c5
--changeset_4780804c-d760-43fe-ab06-2ed20bd173c5
content-type: application/http
content-transfer-encoding: binary
POST SurveyQuestionAnswersCollection HTTP/1.1
Content-Length: 631
Content-Type: application/atom+xml
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xml:base="https://xxxxxxxx.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi">
   <content type="application/xml">
      <m:properties>
         <d:ParentObjectID>0279AAC5D4C81EECA8FA1B1E40949A73</d:ParentObjectID>
         <d:QuestionUUID>0279AAC5D4C81EECA6E3E512DCAE6287</d:QuestionUUID>
         <d:QuestionAnswerOptionUUID>0279AAC5D4C81EECA6E3E512DCB08287</d:QuestionAnswerOptionUUID>
         <d:Date>2022-03-01T00:00:00</d:Date>
      </m:properties>
   </content>
</entry>
--changeset_4780804c-d760-43fe-ab06-2ed20bd173c5--
--batch--<br>

But the system returns the following errors:

HTTP/1.1 500 Internal Server Error
Content-Type: application/xml
Content-Length: 203
location: 
dataserviceversion: 2.0
<?xml version="1.0" encoding="utf-8"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
	<code>ERROR</code>
	<message xml:lang="pt">Insert an end date.</message>
</error>HTTP/1.1 500 Internal Server Error
Content-Type: application/xml
Content-Length: 202
location: 
dataserviceversion: 2.0
<?xml version="1.0" encoding="utf-8"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
	<code>ERROR</code>
	<message xml:lang="pt">Insert a start date.</message>
</error>

Please can you suggest how the request body should be constructed to avoid these errors?

Regards!

Accepted Solutions (0)

Answers (2)

Answers (2)

migsafa
Explorer
0 Kudos

Hello!

We achieved posting the date interval inside this entity:

https://xxxxxx.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi/SurveyResponseItemCollection('xxxxxxxxxxxxxxxxxxxxx')/SurveyQuestionAnswers

Sent like this from CPI

{
    "survey": "0279AAC5D4C81EECAAAA3A75BE8E4CC3",
    "questions": [ 
        {
            "questionObjectID": "0279AAC5D4C81EECA6E3E512DCAE6287",
            "questionTypeCode": 9,
            "answer": {
                "value": {
                    "startDate": {
                        "questionAnswerOptionUUID": "0279AAC5D4C81EECA6E3E512DCB06287",
                        "value": "2022-02-01T00:00:00"
                    },
                    "endDate": {
                        "questionAnswerOptionUUID": "0279AAC5D4C81EECA6E3E512DCB08287",
                        "value": "2022-03-01T00:00:00"
                    }
                }
            }
        }
    ]
}<br>

Submitted in C4C:

HTTP/1.1 201 Created
Content-Type: application/atom+xml;type=entry
Content-Length: 2356
location: https://xxxxxxxx.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi/SurveyQuestionAnswersCollection('061D64C1445C1EDCAAAA4A80446C117F')
dataserviceversion: 2.0
etag: W/"datetimeoffset'2022-03-03T18%3A48%3A19.9971510Z'"
cache-control: no-cache, no-store
<?xml version="1.0" encoding="utf-8"?><entry m:etag="W/"datetimeoffset'2022-03-03T18%3A48%3A19.9971510Z'"" xml:base="https://xxxxxx.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi/" xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"><id>https://xxxxxx.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi/SurveyQuestionAnswersCollection('061D64C1445C1EDCAAAA4A80446C117F')</id><title type="text">SurveyQuestionAnswersCollection('061D64C1445C1EDCAAAA4A80446C117F')</title><updated>2022-03-21T20:06:02Z</updated><category term="c4codata.SurveyQuestionAnswers" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/><link href="SurveyQuestionAnswersCollection('061D64C1445C1EDCAAAA4A80446C117F')" rel="edit" title="SurveyQuestionAnswers"/><link href="SurveyQuestionAnswersCollection('061D64C1445C1EDCAAAA4A80446C117F')/SurveyResponseItem" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/SurveyResponseItem" type="application/atom+xml;type=entry" title="SurveyResponseItem"/><link href="SurveyQuestionAnswersCollection('061D64C1445C1EDCAAAA4A80446C117F')/SurveyResponseRoot" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/SurveyResponseRoot" type="application/atom+xml;type=entry" title="SurveyResponseRoot"/><content type="application/xml"><m:properties><d:ObjectID>061D64C1445C1EDCAAAA4A80446C117F</d:ObjectID><d:ParentObjectID>0279AAC5D4C81EECAAAA3A75BE8E4CC3</d:ParentObjectID><d:QuestionUUID>0279AAC5D4C81EECA6E3E512DCAE6287</d:QuestionUUID><d:QuestionAnswerOptionUUID>0279AAC5D4C81EECA6E3E512DCB06287</d:QuestionAnswerOptionUUID><d:QuestionRatingUUID>00000000000000000000000000000000</d:QuestionRatingUUID><d:QuestionResponseOptionUUID>00000000000000000000000000000000</d:QuestionResponseOptionUUID><d:QuestionTypeCode>9</d:QuestionTypeCode><d:QuestionTypeCodeText>Intervalo de datas</d:QuestionTypeCodeText><d:Amount>0.000000</d:Amount><d:CurrencyCode/><d:CurrencyCodeText/><d:Date>2022-02-01T00:00:00</d:Date><d:NumericValue>0</d:NumericValue><d:Quantity>0.00000000000000</d:Quantity><d:UnitOfMeasure/><d:UnitOfMeasureText/><d:AttributeAssigneeID/><d:AttributeSetID/><d:AttributeID/><d:Text/><d:ETag>2022-03-03T18:48:19.9971510Z</d:ETag></m:properties></content></entry>
HTTP/1.1 201 Created
Content-Type: application/atom+xml;type=entry
Content-Length: 2356
location: https://xxxxxxxx.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi/SurveyQuestionAnswersCollection('061D64C1445C1EDCAAAA4A80446C317F')
dataserviceversion: 2.0
etag: W/"datetimeoffset'2022-03-03T18%3A48%3A19.9971510Z'"
cache-control: no-cache, no-store
<?xml version="1.0" encoding="utf-8"?><entry m:etag="W/"datetimeoffset'2022-03-03T18%3A48%3A19.9971510Z'"" xml:base="https://xxxxxxx.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi/" xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"><id>https://xxxxxx.crm.ondemand.com/sap/c4c/odata/v1/c4codataapi/SurveyQuestionAnswersCollection('061D64C1445C1EDCAAAA4A80446C317F')</id><title type="text">SurveyQuestionAnswersCollection('061D64C1445C1EDCAAAA4A80446C317F')</title><updated>2022-03-21T20:06:02Z</updated><category term="c4codata.SurveyQuestionAnswers" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/><link href="SurveyQuestionAnswersCollection('061D64C1445C1EDCAAAA4A80446C317F')" rel="edit" title="SurveyQuestionAnswers"/><link href="SurveyQuestionAnswersCollection('061D64C1445C1EDCAAAA4A80446C317F')/SurveyResponseItem" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/SurveyResponseItem" type="application/atom+xml;type=entry" title="SurveyResponseItem"/><link href="SurveyQuestionAnswersCollection('061D64C1445C1EDCAAAA4A80446C317F')/SurveyResponseRoot" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/SurveyResponseRoot" type="application/atom+xml;type=entry" title="SurveyResponseRoot"/><content type="application/xml"><m:properties><d:ObjectID>061D64C1445C1EDCAAAA4A80446C317F</d:ObjectID><d:ParentObjectID>0279AAC5D4C81EECAAAA3A75BE8E4CC3</d:ParentObjectID><d:QuestionUUID>0279AAC5D4C81EECA6E3E512DCAE6287</d:QuestionUUID><d:QuestionAnswerOptionUUID>0279AAC5D4C81EECA6E3E512DCB08287</d:QuestionAnswerOptionUUID><d:QuestionRatingUUID>00000000000000000000000000000000</d:QuestionRatingUUID><d:QuestionResponseOptionUUID>00000000000000000000000000000000</d:QuestionResponseOptionUUID><d:QuestionTypeCode>9</d:QuestionTypeCode><d:QuestionTypeCodeText>Intervalo de datas</d:QuestionTypeCodeText><d:Amount>0.000000</d:Amount><d:CurrencyCode/><d:CurrencyCodeText/><d:Date>2022-03-01T00:00:00</d:Date><d:NumericValue>0</d:NumericValue><d:Quantity>0.00000000000000</d:Quantity><d:UnitOfMeasure/><d:UnitOfMeasureText/><d:AttributeAssigneeID/><d:AttributeSetID/><d:AttributeID/><d:Text/><d:ETag>2022-03-03T18:48:19.9971510Z</d:ETag></m:properties></content></entry>

Hope this helps.

Regards

palu
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Sanchez,

Kindly check the below Odata API Documentation.

https://help.sap.com/doc/d0f9ba822c08405da7d88174b304df84/CLOUD/en-US/index.html#/topic/QuestionAnsw...

POST Method is not allowed for this OData Entity.

You can make only GET call.

Regards,

Palani.