Getting an error when trying to run an Import Action using Python3
Hi,
I’m new to Anaplan and am trying to automate the process of refreshing data from a file that has been previously uploaded and imported to a module.
I’m referring to the Apiary and this github repo https://github.com/cdhippen/Anaplan-Python3-Scripts/blob/master/Action%20scripts/action.py
I’ve created a certificate file and am able to connect to Anaplan and do things like getting a list of all workspaces, models, files, actions, etc. However, I get an error (404) when I try to run the action of importing a file. Following is the code snippet:
url = (f'https://api.anaplan.com/1/3/workspaces/{wGuid}/models/{mGuid}/' +
f'actions/{file_id}/tasks')
print(url)
action = requests.post(url, data='{"localeName": "en_US"}', headers=postHeaders)
print('Action status code: ' + str(action.status_code))
with open('postAction.json', 'wb') as f:
f.write(action.text.encode('utf-8'))
Following is the response returned b yAnaplan:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Anaplan</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="viewport" content="width = 960">
<link rel="shortcut icon" href="lib/anaplan/themes/original/images/favicon.ico">
<style type="text/css">
@import "lib/dojo/resources/dojo.css";
html {
overflow: auto;
}
</style>
</head>
<body>
<div id="pageWrap" class="pageWrap">
<div class="banner"><h1>An error has occurred whilst processing your request:</h1></div>
<div><pre class="original">Not Found</pre></div>
<div>Please close your browser window and try again.</div>
<div>If the problem persists then please contact Anaplan Support.</div>
</div>
</body>
</html>
Has anyone else faced this kind of issue? Any pointers on troubleshooting this error would be greatly appreciated.
Best Answer
-
If you're running an import the correct endpoint to use is
/1/3/workspaces/{workspaceId}/models/{modelId}/imports/{importId}/tasks
. You need to substitute your workspace Id, model Id and import Id for {workspaceId}, {modelId} and {importId} respectively. You can get the Ids by querying the API (eg /1/3/workspaces, .../models, .../imports).
1
Answers
-
Thank you so much for this. I was into this issue and tired to tinker around to check if its possible but couldnt get it done. Now that i have seen the way you did it, thanks guys with regards
0