Forum Discussion

TylerBrezler's avatar
TylerBrezler
Qrew Cadet
5 years ago

Trying to implement API_RunImport in python

I've created a couple scripts, with help from a friend who's time is rather limited, to run some API calls, and they are working successfully.  He wrote the first one in python, which was his choosing, and my python skills are limited. However the scripts are simple enough I thought I could modify them slightly and use them for other API calls, which has mostly been working.

API_RunImport is not working. It looks (to me) like it should work, it does not error in the command line when I run it, which I think means the syntax is correct.  But the API call does not fire and the import doesn't run.  When I check QB, nothing has happened.

I tested out the info I'm using as a URL and the URL method works fine, so my user token, app token, dbid and import ID are all accurate. So there's something in the - XML maybe?  Again, it looks correct to me so I'm at a bit of a loss.  I'm guessing it's one of those minor things I'm not seeing because I've been staring at it for too long.

The user token and app token are coded into the script itself.  Then I enter the specific import ID and dbid when I run the script (so I can run a bunch of imports one after another). I also have my actual domain listed in the post URL but modified it for posting here.

import sys
import requests

import_id = sys.argv[1]
dbid = sys.argv[2]

user_token = 'my_user_token'

app_token = 'app_token'

xml = """<qdbapi>
   <usertoken>""" + user_token + """</usertoken>
   <apptoken>""" + app_token + """</apptoken>
   <id>""" + import_id + """</id>
</qdbapi>"""

headers = {'Content-Type': 'application/xml', 'Content-Length': '', 'QUICKBASE-ACTION': 'API_RunImport'}
requests.post('https://mydomain.quickbase.com/db/' + dbid + '?', data=xml, headers=headers)

1 Reply

  • Well, I knew it was something dumb, and apparently I had not added this particular app to my user token in my personal preferences. When I tested it via the URL, it worked fine, so I had assumed I had already completed that step.  I guess the URL method functions differently?

    In any case, I guess this is solved!