AnsweredAssumed Answered

Some guidance with json extraction

Question asked by Paul_Mellor on Feb 21, 2019
Latest reply on Feb 26, 2019 by Paul_Mellor

For most of what i want i can get without issues, however i have 2 problems i am trying to sort out.

 

1) i have this script Source and am Trying to get 1 piece of info Namely the invitation link. (I have cut out 90% or the other data as not relevant.

{

    "data": {

        "account_key": "SrrySfxZZpdmJkm5bNt0GAv6WywTmQgt",

        "credit_number_counter": 1,

        "custom_messages": "{}",

        "contacts": [

            {

                "account_key": "SrrySfxZZpdmJkm5bNt0GAv6WywTmQgt",

                "custom_value2": ""

            }

        ],

        "invoices": [

            {

                "account_key": "SrrySfxZZpdmJkm5bNt0GAv6WywTmQgt",

                "custom_value2": 0,

                "filename": "Invoice_INV0001.pdf",

                "invoice_items": [

                    {

                        "account_key": "SrrySfxZZpdmJkm5bNt0GAv6WywTmQgt",

                        "is_owner": true,

                        "id": 1,

                        "discount": 0

                    }

                ],

                "invitations": [

                    {

                        "id": 1,

                        "key": "xznnl7tboyceegluacpp7pjyerahdpii",

                        "link": "https:\/\/dev.evergreenblades.com.au\/public\/view\/xznnl7tboyceegluacpp7pjyerahdpii",

                        "sent_date": "2019-02-21 03:51:28",

                        "viewed_date": "2019-02-21 03:51:28"

                    }

                ]

            },

            {

                "account_key": "SrrySfxZZpdmJkm5bNt0GAv6WywTmQgt",

                "is_public": true,

                "filename": "Invoice_INV0129.pdf",

                "invoice_items": [],

                "invitations": [

                    {

                        "id": 2,

                        "key": "ml0tbkpqupo6ionvste1wa0eypwdauvz",

                        "link": "https:\/\/dev.evergreenblades.com.au\/public\/view\/ml0tbkpqupo6ionvste1wa0eypwdauvz",

                        "sent_date": "2019-02-21 07:21:49",

                        "viewed_date": "2019-02-21 07:21:49"

                    }

                ]

            }

        ]

    }

}

 

All the info in the data.id section i can get. This is the Full Script i am using to get the data.

Set Error Capture [ On ]

#

Set Variable [ $cmd ; Value: #Assign ( Get (ScriptParameter) ) ]

Insert from URL [ Select ; With dialog: Off ; $invoices ; TO_001____PREFERENCES::GLOBAL_ninja_api_URL & "clients/" & $$Invoice_ID_Link &"?include=invoices.invitations" ; cURL options: " -X GET  -H \"X-Ninja-Token: " & TO_001____PREFERENCES::GLOBAL_ninja_token & "\"" ]

#

#

If [ ( IsEmpty ( JSONGetElement ( $invoices ; "data.id" ) ) or PatternCount ( $invoices ; "error" ) ) ]

Set Variable [ $result ; Value: "error" ]

Else

Set Variable [ $result ; Value: $invoices ]

End If

#

Set Variable [ $create_var_from_json ; Value: JSONCreateVarsFromKeys ( JSONGetElement ( $json_invoices ; "data" ) ; "ninja_" ) ]

Set Variable [ $create_var_from_json ; Value: JSONCreateVarsFromKeys (  JSONGetElement ( $json_invoices; "data.invoices[]" )  ; "ninja_invoices_" ) ]

#

Set Field [ TO_002____Customers::InvNinja_Inv_Link_Key ; JSONGetElement ( $invoices ; ".key" ) ]

Exit Script [ Text Result: $result ]

 

Currently it just fill's up with the whom JSON return in the field.

 

Second question has anyone got a sample script to mutliple lines of json for invoice. Eg i have an invoice that has 2 line items on it (some in the future will be more). how do i code that in JSON.

 

Sorry both are Newbie questions, I had someone else helping me get the JSON from invoice ninja, however even they a 7+ years experience in filemaker could figure it out.

 

Outcomes