RESTAPI : Run a process with an import action

yrignac
Occasional Contributor

RESTAPI : Run a process with an import action

Hi,

 

I'd like to know if it's possible to run a process with an or several import(s)  action in RESTAPI ?

 

I successed to import data using only an Import action.

As we don't have an example on the documentation, I tried to just change the importTrigger function. I change "/imports/{importID}" (see below within ImportTrigger) by "/processes/{processID}" (see below within processImportTrigger)

 

I still send the file within Anaplan using SendData function (see below)

 

But the import doesn't work anymore.

 

Do you have any idea ?

 

Thanks

 

Regards,

Yohan

 

 

 

@classmethod
def sendData(cls, token, wsId, modelId, fileId, chunkCount, content):
# Send the data to Anaplan to update datasource
## First, tell Anaplan API's server it will receive one chunk
headers = {'Authorization': 'AnaplanAuthToken %s' % token, 'Content-Type': 'application/json'}
data = json.dumps({'id': fileId, "chunkCount": chunkCount})
response = requests.post(
urlStem + "/workspaces/" + wsId + "/models/" + modelId + "/files/" + fileId,
headers=headers,
data=data
)
## Now let's send the file
headers2 = {'Authorization': 'AnaplanAuthToken %s' % token, 'Content-Type': 'application/octet-stream'}
response2 = requests.put(
urlStem + "/workspaces/" + wsId + "/models/" + modelId + "/files/" + fileId + "/chunks/" + str(
chunkCount - 1)
,
headers=headers2,
data=content
)
status_code = response2.status_code
return status_code

 

@classmethod
def importTrigger(cls, token, wsId, modelId, importId):
# Finally we trigger the import
headers = {'Authorization': 'AnaplanAuthToken %s' % token, 'Content-Type': 'application/json'}
data = json.dumps({'localeName': "en_US"})
response = requests.post(
urlStem + "/workspaces/" + wsId + "/models/" + modelId + "/imports/" + importId + "/tasks/",
headers=headers,
data=data
)
# Get the taskId
jsonResponse = json.loads(response.content)
taskId = jsonResponse["task"]["taskId"]
return taskId

 

@classmethod

    def processImportTrigger(clstokenworkspaceIdmodelIdprocessId😞
        # Finally we trigger the import
        url_for_taskId = urlStem + "/workspaces/" + workspaceId + "/models/" + modelId + "/processes/" + processId + "/tasks/"
        headers = {'Authorization''AnaplanAuthToken %s' % token'Content-Type''application/json'}
        data = json.dumps({'localeName'"en_US"})
        response = requests.post(
            url_for_taskId,
            headers=headers,
            data=data
        )
# Get the taskId
jsonResponse = json.loads(response.content)
taskId = jsonResponse["task"]["taskId"]
return taskId
1 ACCEPTED SOLUTION

Accepted Solutions
yrignac
Occasional Contributor

Re: RESTAPI : Run a process with an import action

Problem was not on the import function but on sendData.

I've made a small changed with big impact.

Thank you

View solution in original post

1 REPLY 1
yrignac
Occasional Contributor

Re: RESTAPI : Run a process with an import action

Problem was not on the import function but on sendData.

I've made a small changed with big impact.

Thank you

View solution in original post