# CommCare Submissions API - Input XML Formatting

**URL:** <https://forum.dimagi.com/t/commcare-submissions-api-input-xml-formatting/7549>\
**Category:** Developers\
**Created:** [June 23, 2020, 5:52pm UTC](https://forum.dimagi.com/t/commcare-submissions-api-input-xml-formatting/7549 "2020-06-23T17:52:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukepeoples](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/l/e47774/32.png) [@lukepeoples](https://forum.dimagi.com/u/lukepeoples)\
**Post date:** [June 23, 2020, 5:52pm UTC](https://forum.dimagi.com/t/commcare-submissions-api-input-xml-formatting/7549/1 "2020-06-23T17:52:40Z")

</div>

I'm working on developing an external source for data entry that would make use of the Submission API but am unsure of the XML input formatting. In the following article, an example XML file is passed in, but I have not had success using previously-submitted forms from my App. Are there any resources available for formatting OpenRosa XML submissions?

[https://confluence.dimagi.com/display/commcarepublic/Submission+API](https://confluence.dimagi.com/display/commcarepublic/Submission+API)

My account has a Pro subscription.

---

<div class="post-metadata">

**Author:** ![Ethan\_Soergel](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/ethan_soergel/32/543_2.png) [@Ethan\_Soergel](https://forum.dimagi.com/u/Ethan_Soergel)\
**Post date:** [June 23, 2020, 7:14pm UTC](https://forum.dimagi.com/t/commcare-submissions-api-input-xml-formatting/7549/2 "2020-06-23T19:14:58Z")

</div>

> but I have not had success using previously-submitted forms from my App.

That's definitely the best place to start. However, you'll likely need to make a template out of a previously-submitted form and change some parts of it. One big one is the `instanceID` attribute. This is expected to be a UUID that is unique to each form. If CommCare receives multiple forms with the same ID, it will treat them as duplicates. I'd read over the whole form submission, particularly the `meta` block and a `case` block if one exists and ensure anything that should vary from one submission to another does.

---

<div class="post-metadata">

**Author:** ![Clayton\_Sims](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/clayton_sims/32/496_2.png) [@Clayton\_Sims](https://forum.dimagi.com/u/Clayton_Sims)\
**Post date:** [June 23, 2020, 7:16pm UTC](https://forum.dimagi.com/t/commcare-submissions-api-input-xml-formatting/7549/3 "2020-06-23T19:16:21Z")

</div>

Hi,

What issues were you experiencing using previously submitted forms, precisely?

OpenRosa XML submissions are largely just XML documents with the exception of the special transaction blocks like and , knowing what errors you were getting when trying to submit would be helpful, it's likely the issue was with the POST structure rather than the content if you were just rebroadcasting an existing form, but you might also try changing the "instanceid" in the meta block, since that's the UUID for a specific submission, and resubmitting a form with the same UUID will be treated as a duplicate.

---

<div class="post-metadata">

**Author:** ![lukepeoples](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/l/e47774/32.png) [@lukepeoples](https://forum.dimagi.com/u/lukepeoples)\
**Post date:** [June 24, 2020, 3:58pm UTC](https://forum.dimagi.com/t/commcare-submissions-api-input-xml-formatting/7549/4 "2020-06-24T15:58:36Z")

</div>

Thanks for this input! My issue was a combination of bad credentials and the `instanceID` you've mentioned. Once I ran the curl command with -v, I was able to see the authentication error. Here's the command that was suggested by the documentation:

`curl -F ` `"xml_submission_file=@file.xml"``"https://www.commcarehq.org/a/demo/receiver/"``-u username` `@domain` `.commcarehq.org:password`

And here's the successful command:

`curl -F ` `"xml_submission_file=@file.xml"``"https://www.commcarehq.org/a/demo/receiver/[app_id]"``-u username:password`

I also randomly generated an instance ID, and once these two were satisfied, I received the `201 Created` response!

The only issue that's remaining is that while I can see the form submission in CommCare HQ and it's denoted as a Case Registration in the desired App, the case itself is not being created.

The `n0` and `n1` blocks have been updated.

Edit: I was able to make the case visible by passing the generated `instanceID` as the `case_id` in the `n0` block.

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![Ethan\_Soergel](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/ethan_soergel/32/543_2.png) [@Ethan\_Soergel](https://forum.dimagi.com/u/Ethan_Soergel)\
**Post date:** [June 24, 2020, 5:39pm UTC](https://forum.dimagi.com/t/commcare-submissions-api-input-xml-formatting/7549/5 "2020-06-24T17:39:55Z")

</div>

Glad to hear you've resolved the authentication issues. Couple things to note:

`-u username@domain.commcarehq.org:password`  
vs  
`-u username:password`

I'm assuming you're using your web user's username for the latter format. That will work, but CommCare expects data to be submitted by mobile workers, and data will show up weirdly in reports (hidden by default, actually) if it's submitted by a web user. I'd recommend creating a mobile worker and using that for the submission. If your mobile worker's name is `test_user` and your project is called `demo` (like in the example), it should be:

`-u test_user@demo.commcarehq.org:password`

* * *

> I was able to make the case visible by passing the generated `instanceID` as the `case_id` in the `n0` block.

Form `instanceID`s and `case_id`s are both expected to be unique identifiers. You should never reuse the same ID - the case should have it's own, separate ID.

---

<div class="post-metadata">

**Author:** ![lukepeoples](https://dimagi.b-cdn.net/letter_avatar_proxy/v4/letter/l/e47774/32.png) [@lukepeoples](https://forum.dimagi.com/u/lukepeoples)\
**Post date:** [June 24, 2020, 11:39pm UTC](https://forum.dimagi.com/t/commcare-submissions-api-input-xml-formatting/7549/6 "2020-06-24T23:39:46Z")

</div>

Thanks! This is really useful.

On a similar note, how would one format the `<attachment>` block? I've been having some trouble replicating image submissions with previously submitted forms, as these do not include the `<attachment>` details, but rather the form and case properties associated with the attachment.

Using this documentation: [casexml20 · dimagi/commcare-core Wiki · GitHub](https://github.com/dimagi/commcare-core/wiki/casexml20), I've attempted `local` and `inline` submissions, and while the submission is successful, and the data is visible in the submission, it is not being mapped to the `question_id` it's associated with, and does not seem to be accessible via the attachments api. In similar previously-submitted forms, a tab for 'attachments' is visible from the form viewer, but the only place I can see information about the api-submitted attachment is in the 'case metadata', but it doesn't look like the image itself is submitted.

Is it possible to provide a local image or binary (base 64) data and have it accessible via the form attachments api? `https://www.commcarehq.org/a/[domain]/api/form/attachment/{form_id}/{attachment_name}`

Is there a separate request that must be submitted to push the file itself?

If this is better for a new thread, I can move it there as well!

---

<div class="post-metadata">

**Author:** ![Ethan\_Soergel](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/ethan_soergel/32/543_2.png) [@Ethan\_Soergel](https://forum.dimagi.com/u/Ethan_Soergel)\
**Post date:** [June 25, 2020, 9:41pm UTC](https://forum.dimagi.com/t/commcare-submissions-api-input-xml-formatting/7549/7 "2020-06-25T21:41:17Z")

</div>

Yeah, you might have better luck in a new thread. I don't know how to submit attachments via the forms API, though that documentation is definitely where I'd start looking to figure it out.

---

<div class="post-metadata">

**Author:** ![Clayton\_Sims](https://dimagi.b-cdn.net/user_avatar/forum.dimagi.com/clayton_sims/32/496_2.png) [@Clayton\_Sims](https://forum.dimagi.com/u/Clayton_Sims)\
**Post date:** [June 26, 2020, 3:28pm UTC](https://forum.dimagi.com/t/commcare-submissions-api-input-xml-formatting/7549/8 "2020-06-26T15:28:06Z")

</div>

So there are two somewhat separate/distinct components for multimedia attachments.

If you are trying to submit multimedia/file attachments with the form, you'll need to POST a multipart/form-data or multipart/mixed HTTP submission, with the images included as part of that post as outlined [in the original form submission API](https://bitbucket.org/javarosa/javarosa/wiki/FormSubmissionAPI).

To associate those attachments with questions in the form, you should include the content-name of the image attachment as the value of the XML element you are associating with the attachment.

The case attachment syntax is separate (it's a mechanism for getting attachments back down to mobile devices), and is not something that is actively supported due to limitations in its utility for our userbase.

-Clayton
