Hello all,
I am having some issues with a script:
import bunch
# set up headers
options = {}
options['headers'] = {}
options['headers']['X-DreamFactory-Api-Key'] = platform.session.api_key
options['headers']['X-DreamFactory-Session-Token'] = platform.session.session_token
# get records using internal URL; call api.get on the user session that was just
# created (this script will only work in post process!)
url = 'user/session'
result = platform.api.get(url)
data = result.read()
jsonData = bunchify(json.loads(data))
if 'error' in jsonData:
raise ValueError(jsonData.error.message)
# save the data from api.get on user/session to local variables
UserId = str(jsonData.id)
Firstname = jsonData.first_name
Lastname = jsonData.last_name
DisplayName = jsonData.name
Email = jsonData.email
# create a simple json object that will be inserted into the custom user data table
post_data = '{"resource": [{"user_oid": ' + UserId + ',"first_name": "' + Firstname + '","last_name": "' + Lastname + '","display_name": "' + DisplayName + '","email_address": "' + Email + '","created_date": "' + '2017-01-01' + '"}]}'
# create a record using internal URL; call api.post with the post data that was built above, data will
# be posted to custom dim_user table
url = 'aws/_table/dim_users?fields=*&id_field=user_oid'
result = platform.api.post(url, post_data)
data = result.read()
jsonData = bunchify(json.loads(data))
if 'error' in jsonData:
raise ValueError(jsonData.error.message)
elif 'resource' not in jsonData or len(jsonData.resource) != 1:
raise ValueError('Unexpected response from url = ' + url)
print "fini"
It never reaches the end of the script, when I check the logs I see:
[2017-04-05 11:40:01] local.DEBUG: [REQUEST] {"Parameters":"{\"login\":\"true\",\"id_field\":\"user_oid\"}","API Key":"xxx","JWT":null}
[2017-04-05 11:40:01] local.DEBUG: API event handled: user.register.post.pre_process
[2017-04-05 11:40:01] local.DEBUG: API event handled: user.register.post.post_process
[2017-04-05 11:40:01] local.DEBUG: script token: 58e4d791529e7
[2017-04-05 11:40:01] local.DEBUG: script token cache: Array
(
[app_id] => 4
[user_id] => 36
)
[2017-04-05 11:40:01] local.INFO: [REQUEST] {"API Version":"2.0","Method":"GET","Service":"user","Resource":"session"}
[2017-04-05 11:40:01] local.DEBUG: [REQUEST] {"Parameters":"[]","API Key":null,"JWT":null}
[2017-04-05 11:40:01] local.DEBUG: API event handled: user.session.get.pre_process
[2017-04-05 11:40:01] local.DEBUG: API event handled: user.session.get.post_process
[2017-04-05 11:40:01] local.DEBUG: API event handled: user.session.get.queued
[2017-04-05 11:40:01] local.INFO: [RESPONSE] {"Status Code":200,"Content-Type":"application/json"}
[2017-04-05 11:40:01] local.DEBUG: script token: 58e4d791529e7
[2017-04-05 11:40:01] local.DEBUG: script token cache: Array
(
[app_id] => 4
[user_id] => 36
)
[2017-04-05 11:40:01] local.INFO: [REQUEST] {"API Version":"2.0","Method":"POST","Service":"aws","Resource":"_table/dim_users"}
[2017-04-05 11:40:01] local.DEBUG: [REQUEST] {"Parameters":"{\"fields\":\"*\",\"id_field\":\"user_oid\"}","API Key":null,"JWT":null}
[2017-04-05 11:40:01] local.DEBUG: API event handled: evvntlyaws._table.{table_name}.post.pre_process
[2017-04-05 11:40:01] local.DEBUG: API event handled: evvntlyaws._table.dim_users.post.pre_process
[2017-04-05 11:40:01] local.DEBUG: API event handled: evvntlyaws._table.{table_name}.post.post_process
[2017-04-05 11:40:01] local.DEBUG: API event handled: evvntlyaws._table.dim_users.post.post_process
[2017-04-05 11:40:01] local.DEBUG: API event handled: evvntlyaws._table.{table_name}.post.queued
[2017-04-05 11:40:01] local.DEBUG: API event handled: evvntlyaws._table.dim_users.post.queued
[2017-04-05 11:40:01] local.INFO: [RESPONSE] {"Status Code":500,"Content-Type":"application/json"}
[2017-04-05 11:40:01] local.INFO: Script 'user.register.post.post_process' output:
POST
{"resource": [{"user_id": 36,"first_name": "test","last_name": "user40","display_name": "test user40","email_address": "test40@junkmail.com","created_date": "2017-01-01"}]}
[2017-04-05 11:40:01] local.DEBUG: API event handled: user.register.post.queued
[2017-04-05 11:40:01] local.INFO: [RESPONSE] {"Status Code":200,"Content-Type":"application/json"}
I see that the there is an error 500 from the post to the aws table. If i take the POST output that I’m printing and use it in API docs then it inserts without an issue. I can’t figure out how to find what the 500 error is from a Python script, and can’t see anything that should cause an issue in the script?
Any help is appreciated