jsonazurewhmcsazure-logic-app-standard

Azure Logic Apps standard parse JSON error


Whenever I pass a simple JSON and simple schema with the parse JSON card in logic apps something like

{
   "Hello":"World"
}

and

{
    "type": "object",
    "properties": {
        "Hello": {
            "type": "string"
        }
    }
}

It processes naturally, but if I try to access the data from an API call from WHMCS GetClientsProducts via an HTTP request I get an error.

schema

{
    "type": "object",
    "properties": {
        "result": {
            "type": "string"
        },
        "clientid": {
            "type": "string"
        },
        "serviceid": {
            "type": "string"
        },
        "pid": {
            "type": "string"
        },
        "domain": {
            "type": "string"
        },
        "totalresults": {
            "type": "integer"
        },
        "startnumber": {
            "type": "integer"
        },
        "numreturned": {
            "type": "integer"
        },
        "products": {
            "type": "object",
            "properties": {
                "product": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "integer"
                            },
                            "clientid": {
                                "type": "integer"
                            },
                            "orderid": {
                                "type": "integer"
                            },
                            "ordernumber": {
                                "type": "integer"
                            },
                            "pid": {
                                "type": "integer"
                            },
                            "regdate": {
                                "type": "string"
                            },
                            "name": {
                                "type": "string"
                            },
                            "translated_name": {
                                "type": "string"
                            },
                            "groupname": {
                                "type": "string"
                            },
                            "translated_groupname": {
                                "type": "string"
                            },
                            "domain": {
                                "type": "string"
                            },
                            "dedicatedip": {
                                "type": "string"
                            },
                            "serverid": {
                                "type": "integer"
                            },
                            "servername": {
                                "type": "string"
                            },
                            "serverip": {},
                            "serverhostname": {},
                            "suspensionreason": {
                                "type": "string"
                            },
                            "firstpaymentamount": {
                                "type": "string"
                            },
                            "recurringamount": {
                                "type": "string"
                            },
                            "paymentmethod": {
                                "type": "string"
                            },
                            "paymentmethodname": {
                                "type": "string"
                            },
                            "billingcycle": {
                                "type": "string"
                            },
                            "nextduedate": {
                                "type": "string"
                            },
                            "status": {
                                "type": "string"
                            },
                            "username": {
                                "type": "string"
                            },
                            "password": {
                                "type": "string"
                            },
                            "subscriptionid": {
                                "type": "string"
                            },
                            "promoid": {
                                "type": "integer"
                            },
                            "overideautosuspend": {
                                "type": "integer"
                            },
                            "overidesuspenduntil": {
                                "type": "string"
                            },
                            "ns1": {
                                "type": "string"
                            },
                            "ns2": {
                                "type": "string"
                            },
                            "assignedips": {
                                "type": "string"
                            },
                            "notes": {
                                "type": "string"
                            },
                            "diskusage": {
                                "type": "integer"
                            },
                            "disklimit": {
                                "type": "integer"
                            },
                            "bwusage": {
                                "type": "integer"
                            },
                            "bwlimit": {
                                "type": "integer"
                            },
                            "lastupdate": {
                                "type": "string"
                            },
                            "customfields": {
                                "type": "object",
                                "properties": {
                                    "customfield": {
                                        "type": "array",
                                        "items": {
                                            "type": "object",
                                            "properties": {
                                                "id": {
                                                    "type": "integer"
                                                },
                                                "name": {
                                                    "type": "string"
                                                },
                                                "translated_name": {
                                                    "type": "string"
                                                },
                                                "value": {
                                                    "type": "string"
                                                }
                                            }
                                        }
                                    }
                                }
                            },
                            "configoptions": {
                                "type": "object",
                                "properties": {
                                    "configoption": {
                                        "type": "array",
                                        "items": {
                                            "type": "object",
                                            "properties": {
                                                "id": {
                                                    "type": "integer"
                                                },
                                                "option": {
                                                    "type": "string"
                                                },
                                                "type": {
                                                    "type": "string"
                                                },
                                                "value": {
                                                    "type": "string"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

Even though this schema was generated with the payload that I am requesting for within the HTTP Request prior to the Parse JSON card.


Solution

  • After reproducing from my end, I faced the similar issue.

    enter image description here

    This is because the body that is received from trigger body is not of json type (string type). Once I replaced triggedBody() with json(triggedBody()) I could able to get the desired result.

    enter image description here

    I have taken a sample data from your provided schema and did the same as below.

    To make the process easy, First try to select the property that is required.

    enter image description here

    Then navigate to your code view and replace code as below.

    enter image description here

    enter image description here

    "For_each": {
                    "actions": {
                        "Compose": {
                            "inputs": "@items('For_each')?['customfields']",
                            "runAfter": {},
                            "type": "Compose"
                        }
                    },
                    "foreach": "@json(triggerBody())?['products']?['product']",
                    "runAfter": {},
                    "type": "Foreach"
                }
    

    Results:

    enter image description here