Data360 Analyze

 View Only
  • 1.  Parsing Jsons from d360 rest api

    Posted 02-03-2021 08:34

    Hi,
    I'm currently tyring to use the graph that list all users from: https://support.infogix.com/hc/en-us/articles/360042748714-How-to-List-Users-in-Analyze

    However, i get an error when i try to parse the Json for the users.

    The error says: 

    Field "lastName" does not exist on output (0) "out1". Error in "ProcessRecords" at line "10".

    I've tried to add it as a variable in the configureFields part of the Transformer node but then i simply get another error due to a Unknown Type (using str).

    The Json looks as followed :

    {
      "users" : [ {
        "user" : {
        "id" : "xxxxx-yyyy-zzzz-aaaa-bbbb",
        "tenant" : "defaultTenant",
        "name" : "John",
        "imported" : true,
        "active" : true,
        "state" : "ACTIVE",
        "principalImportDetails" : {
        "uniqueImportReference" : "xxxx,yyyy,zzzz",
        "importSource" : "xxxx,yyyy,zzz",
        "removedFromSource" : false
        },
        "attributes" : null,
        "firstName" : null,
        "lastName" : null,
        "emailAddress" : null
       }
      }
     ]
    }

    The code that is used in the Transformer node looks like this (Default from the downloaded graph):
    ConfigureFields

    out1 += in1
    out1.id=str
    out1.name=str
    out1.principalImportDetails=str
    out1.active=str
    out1.state=str
    out1.imported=str
    out1.tenant=str

    out1 -= in1.BaseURL
    out1 -= in1.LTK
    out1 -= in1.URL
    out1 -= in1.response
    out1 -= in1.StatusCode
    out1 -= in1.StatusMessage

    import json

    ProcessRecords

    response=json.loads(fields.response)
    if in1.StatusCode<>200:
      node.logger.error("Failed:"+in1.StatusMessage)
      raise node.fail()
    out1+=in1

    users=response['users']
    for j in users:
      user=j['user']
      out1 += user
      node.write(0,out1)


    When i manually extract all the fields it works but i assume this should work automatically (assuming the graph on the site was correct).
    The bottom 4 fields about the FirstName, Lastname, Attributes and emailAddress never work.
    When i use a JSON data node. It extracts all the fields properly except the 4 null value fields at the bottom.

    Am i missing something here? How do i get those last 4 fields and why do i get the error in the first place when i run the graph as it was without chaning the transformer node?

    Thanks,
    Jurgen



  • 2.  RE: Parsing Jsons from d360 rest api

    Employee
    Posted 02-03-2021 11:24

    The addtibutes, firstName,lastName and emailAddress elements were added to a user's profile in a relatively recent release. It looks like that data flow has not been modified to handle the presence of the additional fields.

    You can modify the script in the 'Parse Json' Transform node's ConfigureFields property so that they are handled correctly by inserting the following lines:

    out1.attributes=unicode
    out1.firstName=unicode
    out1.lastName=unicode
    out1.emailAddress=unicode

     

    The above changes have been made in the attached data flow.

     

    Attached files

    D3SA_List_Users_367 - 3 Feb 2021.lna

     



  • 3.  RE: Parsing Jsons from d360 rest api

    Employee
    Posted 02-03-2021 11:35

    The JSON Data node does not output a field when all of the values of a particular attribute are null.



  • 4.  RE: Parsing Jsons from d360 rest api

    Posted 02-04-2021 03:23

    <x-zendesk-user data-user-name="Adrian Williams">366746295667</x-zendesk-user> Thank's a lot for this info! Good to know that the JSON Data node ignores attributes if they are all null.

    Regarding the Transform node, i actualy tried to do this but got an error. I get the same if i run the model you've attached. It says: 

    java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Unknown type: dict Error executing "ProcessRecords" at line "10"

    I assume its having problems saving a null into unicode but cant tell for sure (very new to both d360 and python)