Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3340850
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:39:18+00:00 2026-05-18T00:39:18+00:00

I need to pull some data from the API. It returns the GET in

  • 0

I need to pull some data from the API. It returns the GET in XML and I have having some issues trying to figure out how to assign some of the data from the API to fields in my model in django/python.

The API for activeCollab does not allow me to create my own projectID number, it automatically generates the number for me. So I would like to take that number, then assign it to my API_id field in my project model. Could someone help me figure out how to take the XML that the GET returns and assign it to one of my fields.

ActiveCollab API Documentation for projects:
http://www.activecollab.com/docs/manuals/developers/api/projects

Here is my models.py

class Project(models.Model):
client = models.ForeignKey(Clients, related_name='projects')
created_by = models.ForeignKey(User, related_name='created_by')


#general information
API_id = models.IntegerField(max_length=10, verbose_name='aC ProjectID', null=True, blank=True)
proj_name = models.CharField(max_length=255, verbose_name='Project Name')
pre_quote = models.CharField(max_length=3)
quote = models.IntegerField(max_length=10, verbose_name='Quote #', unique=True)
estimator = models.ForeignKey(User, related_name='Estimator', null=True)
desc = models.TextField(verbose_name='Description', null=True, blank=True)
starts_on = models.DateField(verbose_name='Start Date')
due_date = models.DateField(verbose_name='Due Date', null=True, blank=True)
completed_on = models.DateField(verbose_name='Finished On', null=True, blank=True)
notes = models.TextField(verbose_name='Notes', null=True, blank=True)

Views.py

def addProject(request):
if request.method == 'POST':
    form = AddSingleProjectForm(request.POST)
    if form.is_valid():
        project = form.save(commit=False)
        project.created_by = request.user 
        today = datetime.date.today()
        project.pre_quote = "%s-" % (str(today.year)[2:4])
        project.quote = Project.objects.latest().quote+1
        project.save()

        project.status.create(
                value = form.cleaned_data.get('status', None)
        )            

        #API activeCollab
        params = urllib.urlencode({
              'format':'xml',
              'submitted':'submitted',
              'project[name]': project.proj_name,
              'project[overview]': project.desc,
              'project[starts_on]': project.starts_on,
              'project[leader_id]': 10,
        })
        req = urllib2.Request("web_url/public/api.php?path_info=/projects/add&token=####################", params)
        f = urllib2.urlopen(req)
        print f.read()


        return HttpResponseRedirect('/project/')
else:
    form = AddSingleProjectForm()

return render_to_response('project/addProject.html', {
'form': form, 'user':request.user}, context_instance=RequestContext(request))

Any suggestions will be appreciated.

Steve

Ps. The api call that I have shown is to create a new project

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:39:19+00:00Added an answer on May 18, 2026 at 12:39 am

    Having looked at the link you posted… something like this might get you started, using lxml and xpath:

    >>> from lxml import etree
    >>> doc = etree.XML("""<projects>
    ...   <project>
    ...     <id>1</id>
    ...     <name>
    ...       <![CDATA[First Project]]>
    ...     </name>
    ...     <overview>
    ...       <![CDATA[<p>This is overview of the first project</p>]]>
    ...     </overview>
    ...     <status>
    ...       <![CDATA[active]]>
    ...     </status>
    ...     <type>...</type>
    ...     <permalink>...</permalink>
    ...     <leader_id>...</leader_id>
    ...     <company_id>...</company_id>
    ...     <group_id>...</group_id>
    ...   </project>
    ... </projects>""")
    >>> data = {}
    >>> for a in doc.xpath('/projects/project/*'):
    ...   data[a.tag] = str(a.text).strip()
    ...
    >>> data
    {'company_id': '...',
     'group_id': '...',
     'id': '1',
     'leader_id': '...',
     'name': 'First Project',
     'overview': '<p>This is overview of the first project</p>',
     'permalink': '...',
     'status': 'active',
     'type': '...'}
    

    Update

    Slightly more explicit help:

    Assuming you have an from lxml import etree in your file. here’s a snippet for your addProject function:

    req = urllib2.Request("web_url/public/api.php?path_info=/projects/add&token=####################", params)
    resp = urllib2.urlopen(req)
    resp_data = f.read()
    if not resp.code == 200 and resp.headers.get('content-type') == 'text/xml':
      # Do your error handling.
      raise Exception('Unexpected response',req,resp)
    data = etree.XML(resp_data)
    api_id = int(data.xpath('/project/id/text()')[0])
    project.API_id = api_id
    project.save()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to pull some BLOB data from a SQL Server 2005 database and
I need to pull some data from Java into C#. I am already exposing
I need to use a query which will pull data from a field when
I am using Flot to chart some data that I pull back from the
I need to pull item quantity from a DB2 database from an aspx page
I have a directory full of files and I need to pull the headers
I need to match a string holiding html using a regex to pull out
I need to a script that will pull up the Task Manager in Vista
In the uncompressed situation I know I need to read the wav header, pull
Need a function that takes a character as a parameter and returns true if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.