How to get xform definition out via api

Hi all,

We want to pull out the xform definition via the api (so that we can, for
example, display the questions in the same order as in CommCare, and
present the human readable question text).

We couldn’t see how to do this from the commcare documentation on the wiki.

Reading the code, we thought the following looked promising:

urlpatterns = patterns(‘corehq.apps.app_manager.views’,

(r’^xform/(?P<form_unique_id>[\w-]+)/$’, ‘xform_display’),

However, using this form e.g.
https://www.commcarehq.org/a/testapi/apps/xform/315c73e1-bc8b-40bb-8c1e-11aa94774ba2/
(we pulled the form_unique_id from the form’s id field) gives us a 500
error.

Obviously we’re not wedded to this method, just looking for a way to get
the xform definition.

We are able to get the xform via the commcarehq interface, but haven’t
found a way to do it generically.

Many thanks,

Sarah Bird

Hi Sarah,

If I’m understanding you correctly you just want to get the raw xml
definition file in a given app/module/form?

This is not supported via the APIs yet, although is something we eventually
planning on adding. However it should still be possible to do via the
current URL structure.

For built apps you can find this by going to the release manager and
clicking “deploy” -> view source files. From there you can get links to the
forms and should be able to reverse engineer the url structure.

For unbuilt apps you can replace /view/ in the url with /download/ and get
to the same page.

Note that since this is not an official API the url structure might change
at any time (which would likely break your app). We don’t have plans to
change it, but rely on it at your own risk.

I’d recommend switching to the API as soon as we add support for that (and
we’ll let you know when that’s the case).

Cory

··· On Tue, Feb 12, 2013 at 6:38 AM, Sarah Bird wrote:

Hi all,

We want to pull out the xform definition via the api (so that we can, for
example, display the questions in the same order as in CommCare, and
present the human readable question text).

We couldn’t see how to do this from the commcare documentation on the wiki.

Reading the code, we thought the following looked promising:

urlpatterns = patterns(‘corehq.apps.app_manager.views’,


(r’^xform/(?P<form_unique_id>[\w-]+)/$’, ‘xform_display’),

However, using this form e.g.
https://www.commcarehq.org/a/testapi/apps/xform/315c73e1-bc8b-40bb-8c1e-11aa94774ba2/(we pulled the form_unique_id from the form’s id field) gives us a 500
error.

Obviously we’re not wedded to this method, just looking for a way to get
the xform definition.

We are able to get the xform via the commcarehq interface, but haven’t
found a way to do it generically.

Many thanks,

Sarah Bird


You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Cory,

I’m not seeing a view source files link, when I click deploy? What am I
missing?

Thanks,

Bird

··· On Tue, Feb 12, 2013 at 4:34 PM, Cory Zue wrote:

Hi Sarah,

If I’m understanding you correctly you just want to get the raw xml
definition file in a given app/module/form?

This is not supported via the APIs yet, although is something we
eventually planning on adding. However it should still be possible to do
via the current URL structure.

For built apps you can find this by going to the release manager and
clicking “deploy” -> view source files. From there you can get links to the
forms and should be able to reverse engineer the url structure.

For unbuilt apps you can replace /view/ in the url with /download/ and get
to the same page.

Note that since this is not an official API the url structure might change
at any time (which would likely break your app). We don’t have plans to
change it, but rely on it at your own risk.

I’d recommend switching to the API as soon as we add support for that (and
we’ll let you know when that’s the case).

Cory

On Tue, Feb 12, 2013 at 6:38 AM, Sarah Bird sarah.birdman@gmail.comwrote:

Hi all,

We want to pull out the xform definition via the api (so that we can, for
example, display the questions in the same order as in CommCare, and
present the human readable question text).

We couldn’t see how to do this from the commcare documentation on the
wiki.

Reading the code, we thought the following looked promising:

urlpatterns = patterns(‘corehq.apps.app_manager.views’,


(r’^xform/(?P<form_unique_id>[\w-]+)/$’, ‘xform_display’),

However, using this form e.g.
https://www.commcarehq.org/a/testapi/apps/xform/315c73e1-bc8b-40bb-8c1e-11aa94774ba2/(we pulled the form_unique_id from the form’s id field) gives us a 500
error.

Obviously we’re not wedded to this method, just looking for a way to get
the xform definition.

We are able to get the xform via the commcarehq interface, but haven’t
found a way to do it generically.

Many thanks,

Sarah Bird


You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


skype: birdsarah
email: sbird@alum.mit.edu
web: www.sarahbird.org | www.bonvaya.com

Hi Sarah,

Apologies, that link actually only shows up for us superusers since it’s
not useful to most people and I forgot that.

You can hit the URL directly with the following format:

https://www.commcarehq.org/a/[domain]/apps/download/[build-id]/

The build id is a long series of letters and numbers that you can find in
the URL of any of the other deploy links.

Cory

··· On Tue, Feb 12, 2013 at 12:05 PM, Sarah Bird wrote:

Hi Cory,

I’m not seeing a view source files link, when I click deploy? What am I
missing?

Thanks,

Bird

On Tue, Feb 12, 2013 at 4:34 PM, Cory Zue czue@dimagi.com wrote:

Hi Sarah,

If I’m understanding you correctly you just want to get the raw xml
definition file in a given app/module/form?

This is not supported via the APIs yet, although is something we
eventually planning on adding. However it should still be possible to do
via the current URL structure.

For built apps you can find this by going to the release manager and
clicking “deploy” -> view source files. From there you can get links to the
forms and should be able to reverse engineer the url structure.

For unbuilt apps you can replace /view/ in the url with /download/ and
get to the same page.

Note that since this is not an official API the url structure might
change at any time (which would likely break your app). We don’t have plans
to change it, but rely on it at your own risk.

I’d recommend switching to the API as soon as we add support for that
(and we’ll let you know when that’s the case).

Cory

On Tue, Feb 12, 2013 at 6:38 AM, Sarah Bird sarah.birdman@gmail.comwrote:

Hi all,

We want to pull out the xform definition via the api (so that we can,
for example, display the questions in the same order as in CommCare, and
present the human readable question text).

We couldn’t see how to do this from the commcare documentation on the
wiki.

Reading the code, we thought the following looked promising:

urlpatterns = patterns(‘corehq.apps.app_manager.views’,


(r’^xform/(?P<form_unique_id>[\w-]+)/$’, ‘xform_display’),

However, using this form e.g.
https://www.commcarehq.org/a/testapi/apps/xform/315c73e1-bc8b-40bb-8c1e-11aa94774ba2/(we pulled the form_unique_id from the form’s id field) gives us a 500
error.

Obviously we’re not wedded to this method, just looking for a way to get
the xform definition.

We are able to get the xform via the commcarehq interface, but haven’t
found a way to do it generically.

Many thanks,

Sarah Bird


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


skype: birdsarah
email: sbird@alum.mit.edu
web: www.sarahbird.org | www.bonvaya.com


You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Cory,

Bit baffled, sorry :s

I am getting a link like this:
https://www.commcarehq.org/a/[domain]/apps/download/[build-id]/modules-0/forms-0.xml

First:

  • Given that I already have cases and forms independent of what build I’m
    on, using the build-id seems problematic - where would I get it from? I
    can’t see it in the case / form data
    Second:
  • The URL is not using a form-unique-id it seems to be using
    module-<module_id> & form-<form_id> where module_id and form_id are 0,1 etc
  • how do I know what the module_id and form_id are for a particular form?

Things I readily know: case_unique_id, xform_unique_id (the form instance
not the form definition), domain_name

Cheers,

Bird

··· On Tue, Feb 12, 2013 at 5:24 PM, Cory Zue wrote:

Hi Sarah,

Apologies, that link actually only shows up for us superusers since it’s
not useful to most people and I forgot that.

You can hit the URL directly with the following format:

https://www.commcarehq.org/a/[domain]/apps/download/[build-id]/

The build id is a long series of letters and numbers that you can find in
the URL of any of the other deploy links.

Cory

On Tue, Feb 12, 2013 at 12:05 PM, Sarah Bird sbird@alum.mit.edu wrote:

Hi Cory,

I’m not seeing a view source files link, when I click deploy? What am I
missing?

Thanks,

Bird

On Tue, Feb 12, 2013 at 4:34 PM, Cory Zue czue@dimagi.com wrote:

Hi Sarah,

If I’m understanding you correctly you just want to get the raw xml
definition file in a given app/module/form?

This is not supported via the APIs yet, although is something we
eventually planning on adding. However it should still be possible to do
via the current URL structure.

For built apps you can find this by going to the release manager and
clicking “deploy” -> view source files. From there you can get links to the
forms and should be able to reverse engineer the url structure.

For unbuilt apps you can replace /view/ in the url with /download/ and
get to the same page.

Note that since this is not an official API the url structure might
change at any time (which would likely break your app). We don’t have plans
to change it, but rely on it at your own risk.

I’d recommend switching to the API as soon as we add support for that
(and we’ll let you know when that’s the case).

Cory

On Tue, Feb 12, 2013 at 6:38 AM, Sarah Bird sarah.birdman@gmail.comwrote:

Hi all,

We want to pull out the xform definition via the api (so that we can,
for example, display the questions in the same order as in CommCare, and
present the human readable question text).

We couldn’t see how to do this from the commcare documentation on the
wiki.

Reading the code, we thought the following looked promising:

urlpatterns = patterns(‘corehq.apps.app_manager.views’,


(r’^xform/(?P<form_unique_id>[\w-]+)/$’, ‘xform_display’),

However, using this form e.g.
https://www.commcarehq.org/a/testapi/apps/xform/315c73e1-bc8b-40bb-8c1e-11aa94774ba2/(we pulled the form_unique_id from the form’s id field) gives us a 500
error.

Obviously we’re not wedded to this method, just looking for a way to
get the xform definition.

We are able to get the xform via the commcarehq interface, but haven’t
found a way to do it generically.

Many thanks,

Sarah Bird


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


You received this message because you are subscribed to the Google
Groups “commcare-users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


skype: birdsarah
email: sbird@alum.mit.edu
web: www.sarahbird.org | www.bonvaya.com


You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


skype: birdsarah
email: sbird@alum.mit.edu
web: www.sarahbird.org | www.bonvaya.com

Hey,

Hi Cory,

I am getting a link like this:
https://www.commcarehq.org/a/[domain]/apps/download/[build-id]/modules-0/forms-0.xml

First:

  • Given that I already have cases and forms independent of what build I’m
    on, using the build-id seems problematic - where would I get it from? I
    can’t see it in the case / form data

If you just want the current copy based on the app you can substitute the
app id for the build id.

  • The URL is not using a form-unique-id it seems to be using

module-<module_id> & form-<form_id> where module_id and form_id are 0,1 etc

  • how do I know what the module_id and form_id are for a particular form?

This is indexed by the order you see them when editing your app. They are
also referenced by the xform unique id in the suite file if you want to
pull them from there. Like I mentioned, this isn’t an official or designed
API so you’ll have to do some leg work to make it work.

Feel free to follow up off-list as I don’t think this is super relevant to
anyone else.

Cory

··· On Tue, Feb 12, 2013 at 12:39 PM, Sarah Bird wrote: