I have this code and I want to store the data of auth API into a data extension. I am able to successfully generate the result of API but not able to store that data in a data extension.
You can see my code below:
<script runat="server">
Platform.Load("Core", "1")
var str = Variable.GetValue("@JSON");
var obj = Platform.Function.ParseJSON(str);
var token = obj.access_token;
var auth = 'Bearer ' + token;
var req = new Script.Util.HttpRequest("https://api.socialstudio.radian6.com/v3/users/me");
req.emptyContentHandling = 0;
req.retries = 2;
req.continueOnError = true;
req.contentType = "application/json"
req.setHeader("Authorization", auth);
req.method = "GET";
var resp = req.send();
var resultJSON = Platform.Function.ParseJSON(String(resp.content));
var item = resultJSON.data[0];
Write(item['id']);
var row = Platform.Function.UpsertDE("Auth_API", ["id"], [item['id']], ["username"], [item['username']]);
</script>
The UpsertDE
function is not working and is showing this error while loading the cloud page: 500 - Internal server error.
I have checked the Attributes and the Data Extension name and they are the same.
item
? to make sure that the JSON structure matches? Have you validated that the outputs are as expected? Writing both id and username values? Have you put these into a var and pushed into the function rather than have them raw inside the array? Have you run it without the upsert function to validate it is 100% that function?