Connect to submissions data over OData error: Requested format not acceptable (406)

1. What is the problem? Be very detailed.
I am getting a 406.1 error code (unacceptable requested format) when I try to connect to the submit data using my project's api odata code.
2. What app or server are you using and on what device and operating system? Include version numbers.
odk central 1.2
google chrome Version 91.0.4472.114 (Build officiel) (32 bits)

3. What you have you tried to fix the problem?
Looked around the ODK Central and in documentation. I could not find it anywhere.
4. What steps can we take to reproduce the problem?
N/A
5. Anything else we should know or have? If you have a test form or screenshots or logs, attach below.
N/A

Welcome to the ODK forum, @GAMPINI! We're glad you're here. When you get a chance, please introduce yourself on this forum thread. I'd also encourage you to add a picture as your avatar because it helps build community!

The OData feed is intended primarily for connecting to submission data (that is, for analysis and visualization), and not for submitting data. What is your use case that you are trying to submit data using the "project's API OData code"? Most people submit using either the Android app ODK Collect or Enketo web forms in their browser.

2 Likes

hello @danbjoseph ,
Thanks for the answer, I'm happy to be here. I wanted to retrieve the data which was submitted directly by entering the code in the url of the browser but after having read the documentation I saw that it is necessary to be authenticated to have access to the information of my project. so i implemented this code in php, but i got an error message: {"message":"Required parameter form ID xml attribute missing.","code":400.2,"details":{"field":"form ID xml attribute"}}

<?php
// authentification 
 $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://xxxxxxxxxxxxxxx/v1/sessions");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, TRUE);

curl_setopt($ch, CURLOPT_POSTFIELDS, "{
  \"email\": \"xxxxxxxxxxxxxx@xxxxxx.com\",
  \"password\": \"xxxxxxxxxxxxxx\"
}");

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  "Content-Type: application/json"
));

$response = curl_exec($ch);
var_dump($response);
$json = json_decode($response, true);
$Authorization=  "Authorization: Bearer ".$json['token']."";	

$url = "xxxxxxxxxxxxxxxxx/v1/projects/1/forms/xxxxxxxxx.svc/Submissions";

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array(
 $Authorization
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$resp = curl_exec($ch);
curl_close($ch);
var_dump($resp);

Is the .svc in your URL part of the xmlFormID for the form you are trying to access? Or is that something you're adding on?

my xmlFormID is : id="infoperso",
I was inspired by the example in the API documentation : infoperso.svc

<?php
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://private-948d41-odkcentral.apiary-mock.com/v1/projects/projectId/forms/{xmlFormId}.svc/{table}?%24skip=&%24top=&%24count=&%24wkt=&%24filter=&%24expand=");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);

$response = curl_exec($ch);
curl_close($ch);

var_dump($response);

Hi @GAMPINI! I'm not familiar with PHP, but from your code above, it looks like the HTTP verb might still be POST in the second request. The request to the OData endpoint should use GET.

1 Like