Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
ep513140
Frequent Visitor

Power BI API integration with Unity

I am trying to use a PowerBI API which saves Unity data. I have scoured the internet and I think it might be due to the PowerBI API permissions and not Unity. In order for Unity to write data to the API I have been trying to use the UnityWebRequest. However, I have gotten many errors. I have been testing my API with Postman and Powershell. I am able to "POST" but I can't use "GET", "PUT", or anything else and get a 404 error if I try. I am hoping this won't be an issue because I just want to POST anyway. I am not sure if I need to change the PowerBI API permissions somehow or generate a token, I am new to PowerBI and am using it to post Unity analytics.

I created a PowerBI streaming datasource API with a URL and desired data in the following format:

[ { "Variable 1" :98.6, "Variable 2" :98.6 } ]

Here are two different ways I have tried to code this:

ep513140_1-1702931417275.png

 

This gives me an error of: The type name 'Post' does not exist in the type 'UnityWebRequest'.

 

 

The other way I do it is to change PostData to use UploadHandlerRaw:

 

ep513140_0-1702931396242.png

 

 

 I apologize for the lengthy post but I have been trying to figure this out for weeks now. 

 

UPDATE: I have tried deleting the "new" from the UnityWebRequest.POST line and I now get an 500 Internal Server Error.

 

TLDR: I can only POST from Postman and Powershell, not any other API requests, and I can't do anything from Unity. Any and all help is greatly appreciated.

12 REPLIES 12
ep513140
Frequent Visitor

Thank you so much for the reply. I have been adding the push key to the URL as given from the Power BI API info in the following manner:

 

https://api.powerbi.com/beta/<tenant id>/datasets/<dataset id>/rows?<rows>key=<push key>

 

So I am not sure if this is the problem. Maybe I need to add more headers to the API request? Apologies, I am not well versed in APIs.

you can't add the rows to the URL. those need to go into the request body, and the request must be POST, not GET.

 

Like I showed in my sample code

I have previously been using POST as you suggested, I just now changed the URL to "rows?key=<push key>" so I have deleted the information PowerBI put in the URL with the rows information, however I still get a 500 Internal Server Error. Your sample code is informative but because I am using Unity, there is a different way I am uploading the data with .ToJson and Unity Web Requests as seen in my question post. I really appreciate your patience with me, I have been trying to figure this out for weeks.

You can use Postman or the API sandbox to figure out what the issue with your payload is.

 

This url is for push datasets, but the mechanics are the same as for streaming datasets (minus the key)

Push Datasets - Datasets PostRowsInGroup - REST API (Power BI Power BI REST APIs) | Microsoft Learn

 

If you can show a sample payload and the definitions of your streaming dataset fields I may be able to help you further

It works when I use Postman to POST the following content:

 

[
{
"Experience" :47,
"Confidence" :47
}
]
 
 
When I created the API I made "Experience" and "Confidence" take "Numbers". However from Postman I am unable to use GET or PUT, with an error of: "No HTTP resource was found that matches the request URI: 'http://wabi-west-us-b-primary-redirect.analysis.windows.net/beta/...'"

 

When I print out my player data in JSON format, I get the following output:

{"Experience":3, "Confidence":5}

 

The full stacktrace for the 500 error is:

Error: HTTP/1.1 500 Internal Server Error
0x00007ff729478e4d (Unity) StackWalker::GetCurrentCallstack
0x00007ff72947ddf9 (Unity) StackWalker::ShowCallstack
0x00007ff72a44b121 (Unity) GetStacktrace
0x00007ff72ab0d922 (Unity) DebugStringToFile
0x00007ff7283c97f6 (Unity) DebugLogHandler_CUSTOM_Internal_Log
0x000002627cb5d403 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
0x000002627cb5d31b (Mono JIT Code) UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
0x000002627cb5d020 (Mono JIT Code) UnityEngine.Logger:Log (UnityEngine.LogType,object)
0x000002627cb5cee8 (Mono JIT Code) UnityEngine.Debug:Log (object)
0x000002627cb5cd33 (Mono JIT Code) APIPost/<PostData>d__10:MoveNext () (at C:/Users/ellai/My project (1)/Assets/API_Post.cs:73)
0x000002617fc16470 (Mono JIT Code) UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)
0x000002617fc1659f (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_void_object_intptr (object,intptr,intptr,intptr)
0x00007ff9d943e0d4 (mono-2.0-bdwgc) mono_jit_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-runtime.c:3445)
0x00007ff9d937eb74 (mono-2.0-bdwgc) do_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3066)
0x00007ff9d937ed0c (mono-2.0-bdwgc) mono_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3113)
0x00007ff729397bc4 (Unity) scripting_method_invoke
0x00007ff729376844 (Unity) ScriptingInvocation::Invoke
0x00007ff72933f32a (Unity) Coroutine::Run
0x00007ff72933cd1f (Unity) Coroutine::ContinueCoroutine
0x00007ff728ff9ef3 (Unity) AsyncOperation::InvokeCoroutine
0x00007ff729934f8c (Unity) UnityWebRequestAsyncOperation::InvokeCoroutine
0x00007ff729935171 (Unity) UnityWebRequestProto<UnityWebRequestTransport,AtomicRefCounter,RedirectHelper,ResponseHelper,DownloadHandler,UploadHandler,CertificateHandler,HeaderHelper,AsyncOperation>::Job_InvokeCoroutine
0x00007ff728fad63a (Unity) BackgroundJobQueue::ExecuteMainThreadJobs
0x00007ff72902fb1c (Unity) `InitPlayerLoopCallbacks'::`2'::EarlyUpdateExecuteMainThreadJobsRegistrator::Forward
0x00007ff72900fbda (Unity) ExecutePlayerLoop
0x00007ff72900fd66 (Unity) ExecutePlayerLoop
0x00007ff729016625 (Unity) PlayerLoop
0x00007ff729fd2cbf (Unity) PlayerLoopController::InternalUpdateScene
0x00007ff729fdf89d (Unity) PlayerLoopController::UpdateSceneIfNeededFromMainLoop
0x00007ff729fddba1 (Unity) Application::TickTimer
0x00007ff72a45180a (Unity) MainMessageLoop
0x00007ff72a456910 (Unity) WinMain
0x00007ff72b84133e (Unity) __scrt_common_main_seh
0x00007ffab28c257d (KERNEL32) BaseThreadInitThunk
0x00007ffab3d0aa78 (ntdll) RtlUserThreadStart

Is Unity maybe confused by the 401 ?

When I use Postman to test a GET request, I get the following error:

{
    "error": {
        "code": "",
        "message": "No HTTP resource was found that matches the request URI 'http://wabi-west-us-b-primary-redirect.analysis.windows.net/beta/c6f643f0-4f6b-47f1-90f2-d2ce068e698...<dataset>/rows?key=<key>'."
    }
}
 
This link is different from the api url given by Power BI which is 
 
I tested my Unity script with a different API I generated on another website and I was able to POST and GET, so it seems like it must be an issue with Power BI perhaps redirecting to this second URL? When I use the PowerBI URL in Unity, I get a 404 error using GET and a 500 error using POST.
 
I have looked at this link a few times and am unsure, maybe I need to create an App for the API? Power BI REST APIs for embedded analytics and automation - Power BI REST API | Microsoft Learn
But I can write to the API from PowerShell and Postman so I don't know why Unity would require me to make an app and those wouldn't.

 so it seems like it must be an issue with Power BI perhaps redirecting to this second URL?

Redirects can happen, but maybe Unity didn't expect that?

I tried using the redirect URL 'http://wabi-west-us-b-primary-redirect.analysis.windows.net/beta/c6f643f0-4f6b-47f1-90f2-d2ce068e698...<dataset>/rows?key=<key>'." in Postman for a POST request but it gets stuck sending the request for 30 seconds then times out. Is there anywhere I can see the proper redirect URL?

lbendlin
Super User
Super User

Not clear to me what you are trying to accomplish. Are you attempting to push rows into a streaming dataset?

Yes, I am trying to push data from Unity into a streaming data set so that there is a new row in the streaming dataset. In the code above I have hard coded the data to have "Experience" = 3 and "Confidence"= 5 which is what I would like the row to display after the Unity Web Request completes. However, I either get a 500 Internal Server Error or a 404 error. 

To push rows into a streaming dataset you need to add the push key to the URL.

 

$endpoint = "https://api.powerbi.com/beta/<tenant id>/datasets/<dataset id>/rows?key=<push key>"
Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

Check out the August 2024 Power BI update to learn about new features.

August Carousel

Fabric Community Update - August 2024

Find out what's new and trending in the Fabric Community.