Anaplan & MS Access Transactional API using Python
Hi,
I'm trying to update the data in Anaplan module line items directly from MS Access by converting into json format using Python transactional APIs.
I'm keep getting the "Status code 400" , "Message - Post body is not a valid json". I have tried by printing the json format before sending the data into Anaplan and format is true as i checked the format in jsonlint.com and i tried with different possibilities of error rectification but still throwing the same error again and again.
@StevenBeerthuizen @ryan_kohn @eschau @kevin.cho anybody can help me fix this issue?
Sample Ms access data
Answers
-
Copy out the payload that you're trying to write here, so we can take a look.
0 -
Attached the snapshot the payload and also attached the sample code in the above post
0 -
Do you mind copying what the code is actually generating though? (Sanitised)
Just comparing it with what I've configured in Postman, I don't send it as
{"updates": [….]}
but rather just
[
…
]
where … is what you have defined here
"lineItemId": str(line_item_id), "dimensions": dimensions, "value": value
0 -
{
"updates": [
{
"lineItemId": "XXXXXXXXX",
"dimensions": [
{
"dimensionId": "XXXXXXXX",
"itemId": "XXXXXXXXX"
}
],
"value": "France"
},
{
"lineItemId": "XXXXXXXXXX",
"dimensions": [
{
"dimensionId": "XXXXXXXXX",
"itemId": "XXXXXXXXXXXXX"
}
],
"value": "Sales"
}
]
}
the above is the output of the code snippet0 -
Thanks
Change it to json.dumps(updates…) rather than json.dumps(payload)
Should just be a list of CellWrite objects, you don't need them to be captured in the "updates" object.
i.e.
[ { "lineItemId": "XXXXXXXXX", "dimensions": [ { "dimensionId": "XXXXXXXX", "itemId": "XXXXXXXXX" } ], "value": "France" }, { "lineItemId": "XXXXXXXXXX", "dimensions": [ { "dimensionId": "XXXXXXXXX", "itemId": "XXXXXXXXXXXXX" } ], "value": "Sales" } ]
Based on:
"Ensure the request body is an array of
CellWrite
objects. Each object is for an updated individual cell and its full set of dimensions."0 -
I have tried changing the into json.dumps(updates) and still it throws the same error. And also i have validated the json format and it is correct.
Not understanding why it gives the error
0 -
Hi,
In your python code as you are using json option of request library you will need to post the list formatted data there not the string formatted json_dump. From your format Anaplan payload you could simply return your updates list and send that as json parameter of your request.post.
5 -
+1 to @pyrypeura's solution
if you want to pass through the string format from json.dumps(…), use parameter "data" instead of "json"
You'll still need to get rid of the "updates" object however.
1