Graph XML: use roUrlTransfer

Hello everyone,

I’m new on Roku plateform and I have some questions about XML component functionality !

I am getting a json with roUrlTransfer, and I printed correctly inside value.


    Function getJson() As Object

    searchRequest = CreateObject("roUrlTransfer")
    searchRequest.SetCertificatesFile("common:/certs/ca-bundle.crt")
    searchRequest.AddHeader("X-Roku-Reserved-Dev-Id", "")
    searchRequest.InitClientCertificates()
    searchRequest.SetURL("https://api.tfoumax.fr/catalog/home")
    response = ParseJson(searchRequest.GetToString())

    return response

    End Function

But I wanted to use json response object in XML component file, like:

But the program is stuck at response = getJson line, anyone have an alternative to use my json inside graph XML ?

Thanks in advance !

Max

You can’t create an roUrlTransfer object in the main SceneGraph thread. You’ll need to move that into a Task node.

Thanks your for your reactivity ! I am using now a task but it fail on SetCertificatesFile(“common:/certs/ca-bundle.crt”), (not failed in brs file)

telnet:

Backtrace:
#0 Function init() As Void
file/line: …AAA8F92yB/pkg:/components/getJson.xml(17)
Local Variables:
global rotINTERFACE:ifGlobal
m roAssociativeArray refcnt=3 count:1
searchrequest Invalid


<?xml version="1.0" encoding="utf-8" ?>
 
<component name="getJsonGraph" extends="Task" >  
 
<interface>
  <field id="json-api" type="string" />
</interface>   
 
<script type="text/brightscript" >
<![CDATA[
 
sub init()

    searchRequest = CreateObject("roUrlTransfer")
    searchRequest.SetCertificatesFile("common:/certs/ca-bundle.crt")
    searchRequest.AddHeader("X-Roku-Reserved-Dev-Id", "")
    searchRequest.InitClientCertificates()
    searchRequest.SetURL("myapi-url")
 
    response = ParseJson(searchRequest.GetToString())
        
        For Each categorie In response.categories
        	print categorie.title
    	End For

end sub

]]>
</script>
 
</component>

Run task:

<?xml version="1.0" encoding="utf-8" ?>

<component name = "rowlistcontent" extends = "ContentNode" >

  <script type="text/brightscript" >
    <![CDATA[

    sub init()
    
    m.simpleTask = CreateObject("roSGNode", "getJsonGraph")
    m.simpleTask.control = "RUN"
    
    end sub

    ]]>
  </script>

  <children>

  </children>

</component>

Thanks again for your help

For Task nodes, you need to set m.top.functionName in init(). That indicates which function will be run in the Task thread when you set the control to RUN. It’s that function that will run in the separate thread and allow you to create the roUrlTransfer object.

Thanks you, it works !