Stuck with " 'rootKey' field is needed" error

Hello All,

I added a custom resource to ServiceNow adapter that accesses the Opportunities table. When I "try out" the GET /opportunity endpoint, I get an error

This element does not return a root array for its pluralized responses, so a 'rootKey' field is needed to be set on this resource

'rootKey' required error

When I check the Vendor section, I see that response data was successfully received (see screenshot).

vendor response

The response data has the following format:

{
"result":
[{
"subcontractor_profit":"0",
"sales_stage":"Opportunity Qualification"
}]
}

This shows that "result" has to be set as the rootKey in order to access the opportunity data. I did so (see screenshot below), but I still get the same error.

opportunities endpoint configuration

A hard refresh of the browser does not help. Could it be related to the fact that the opportunity data after "result" key is not an object but an array, enclosed by square brackets? I think this is the likely reason because a different custom endpoint /opportunity/{id} has the same response data format, but with no square brackets. It stopped throwing the 'rootkey' error after I added "result" as a response rootKey. How can I account for the square bracket-enclosed array when defining a rootKey?

  • Hi Yury,

    This is something similar we faced earlier. Can you try to execute the Opportunity End point in PostMan and check whether you are getting the response or not. If you are getting response, it means the endpoint is working fine. The issue which you are talking is related to configuration parameters you have to set and this occurs when your endpoint response contains Nested arrays format  in the Payload response.Can you go through this link once to get some idea about request root key.

  • Thank you Poojitha. Yes, the endpoint does work in Postman. Could you please tell me how you dealt with nested arrays in the response? The knowledge base article on the Response Root Key shows examples where the child property associated with the root key is an object, as in this example where we would use "data" as the rootKey to get the contacts property:

    {

    "data": {

    "contacts": "...."

    }

    }

    But what do we need to do differently when the child property is an array, like this:

    {

    "data": [{

    "contacts": "...."

    }]

    }

    How would you get the contacts property in this case?

  • Hi Yury,

    Could you please attach the screenshot or the json file response of your API Endpoint what you are getting when you are trying to hit in PostMan. By seeing the response we can give some inputs how to handle nested arrays in API Response.

  • Hi Poojitha,

    Here's the json file with response data. It basically looks like this:

    {"result":[{ }],""}

    I suspect the pair of quotes before the last } might be the problem.

    Thank you!

    opp_response_short.txt
    {"result":[{"u_subcontractor_profit_ps_c":"0","u_sales_stage_tprsb_c":"","u_hb_term_c":"Annually","u_start_date_tpr_c":"","u_term_tpr_c":"","u_revenue_fixed_fee_cps_c":"0","u_revenue_fixed_fee_nps_c":"0","sys_updated_on":"2019-04-26 21:42:05","u_profit_clms_c":"0","u_third_party_ms_cost_c":"0","u_uc_nsb_resale_revenue_c":"0","u_start_date_ps_c":"2018-07-02","u_profit_sr_c":"0","u_profit_sps_c":"0","u_opportunity_name":"EY - IVR UCCX Monthly Updates - 14162","u_tprm_profit_c":"0","u_term_rs_c":"","u_mu_cost_c":"0","sys_created_by":"Sugar2SvcNowSync","u_uc_ssf_resale_revenue_c":"0","u_commit_stage_ps_c":"Funnel","u_uc_ssf_resale_cost_c":"0","u_third_party_ps_profit_c":"0","u_term_ms_c":"1","u_sales_stage_rs_c":"Rapport","u_actual_closed_date_tpr_c":"","u_hb_sales_stage_c":"Rapport","u_end_date_ps_c":"2019-06-29","u_uc_csf_resale_revenue_c":"0","u_change_order":"false","u_hb_start_date_c":"","u_sales_stage_ms_c":"Rapport","u_actual_closed_date_sr_c":"","u_uc_ssb_resale_profit_c":"0","u_third_party_ps_cost_c":"0","u_revenue_clps_c":"0","u_commit_stage_tprsb_c":"","u_close_date_tprsf_c":"","u_sales_stage_tprm_c":"","u_revenue_subtotal_ms_c":"0","u_uc_ssn_resale_profit_c":"0","u_cost_sms_c":"0","u_professional_services_total_c":"0","u_cost_nps_c":"0","u_uc_ssn_resale_revenue_c":"0","u_special_instructions_txt_tpr_c":"","u_cost_rs_c":"0","u_ms_renewal_c":"false","u_actual_closed_date_hb_c":"","u_total_contract_value_ms_c":"0","u_net_new_income_cms_c":"0","u_amount":"0","u_uc_csf_resale_profit_c":"0","u_mu_profit_c":"0","u_profit_margin_nms_c":"0","u_setup_fee_nms_c":"0","u_type_sps_c":"","u_uc_nsb_resale_profit_c":"0","u_commit_stage_tpr_c":"","u_cost_cps_c":"0","u_uc_nsn_resale_profit_c":"0","u_hb_commit_stage_c":"Funnel","u_revenue_nps_c":"0","u_special_instructions_rs_c":"false","u_renewal_revenue_clms_c":"0","u_teams":"Global","u_upfront_percent_ps_c":"0","u_commit_stage_opp_c":"Funnel","u_setup_fee_cms_c":"0","u_revenue_cms_c":"0","u_date_modified":"2019-04-25 19:58:10","u_uc_ssb_resale_cost_c":"0","sys_created_on":"2019-04-25 19:58:09","u_cost_clps_c":"0","u_revenue_sr_c":"0","u_actual_close_date_c":"","u_actual_closed_date_ps_c":"","u_uc_nsn_resale_cost_c":"0","u_opportunity_type":"","u_actual_closed_date_tprm_c":"","u_start_date_sr_c":"","u_profit_margin_sms_c":"0","u_snow_sync_time_c":"","u_actual_closed_date_tprsf_c":"","u_parent_opportunity":"","u_managed_services_c":"false","u_hb_end_date_c":"","u_ms_hb_total_revenue_c":"0","u_cost_tpr_c":"0","u_commit_stage_tprh_c":"","u_uc_ssf_resale_profit_c":"0","u_profit_cps_c":"0","u_close_date_ms_c":"","u_revenue_fixed_fee_clps_c":"0","u_mu_revenue_c":"0","u_uc_shw_resale_revenue_c":"0","u_sales_stage_sr_c":"","sys_id":"000dcf5d4f0d73401b59a9d18110c7dc","u_uc_csf_resale_cost_c":"0","u_uc_nsf_resale_revenue_c":"0","u_uc_hw_resale_cost_c":"0","u_tprsb_cost_c":"0","u_close_date_tprh_c":"","u_revenue_sps_c":"0","u_estimated_clps_revenue_c":"0","u_revenue_fixed_fee_sps_c":"0","u_sugar_account_id":"","u_sales_stage_tpr_c":"","u_estimated_cps_revenue_c":"0","u_estimated_sps_revenue_c":"0","u_account_name":{"link":"https://fidelusdev.service-now.com/api/now/v1/table/customer_account/b211e985138dbf009c615cb63244b019","value":"b211e985138dbf009c615cb63244b019"},"u_close_date_tpr_c":"","u_renewal_revenue_cms_c":"0","u_sugar_id":"1f9dce0c-2d56-11e8-8d73-024b2e004070","u_uc_nhw_resale_revenue_c":"0","sys_tags":"","u_revenue_tpr_c":"0","u_profit_nms_c":"0","u_profit_rs_c":"0","u_close_date_rs_c":"","u_ms_hb_annual_revenue_c":"0","u_third_party_ms_revenue_c":"0","u_subcontractor_price_ps_c":"0","u_special_instructions_tpr_c":"false","u_major_upgrade_ms_c":"false","u_special_instructions_text_sr_c":"","u_uc_shw_resale_profit_c":"0","u_sales_stage_tprh_c":"","u_date_closed":"2018-06-30","u_sales_stage_tprsf_c":"","u_start_date_ms_c":"","u_tprsf_revenue_c":"0","u_hb_rate_c":"225","u_end_date_ms_c":"","u_close_date_tprm_c":"","u_cisco_resale_c":"false","u_mu_commit_stage_c":"Funnel","u_uc_csn_resale_profit_c":"0","u_hb_total_revenue_c":"0","u_opportunity_number_c":"14162","u_uc_csb_resale_cost_c":"0","u_description":"\n1. Business Driver: \n\n2. Primarily Contact Driver : \n\n3. Etc.","u_profit_clps_c":"0","u_tprm_revenue_c":"0","u_profit_sms_c":"0","u_setup_fee_clms_c":"0","u_type_nps_c":"","u_hb_total_profit_c":"0","u_third_party_resale_c":"false","u_revenue_rs_c":"0","u_commit_stage_sr_c":"","u_commit_stage_tprsf_c":"","u_uc_ssn_resale_cost_c":"0","u_close_date_tprsb_c":"","u_close_date_sr_c":"","u_mu_sales_stage_c":"Rapport","u_actual_closed_date_mu_c":"","u_revenue_clms_c":"0","u_cost_cms_c":"0","u_net_new_income_sms_c":"0","u_assigned_to":{"link":"https://fidelusdev.service-now.com/api/now/v1/table/sys_user/579cc76513172b009c615cb63244b0c0","value":"579cc76513172b009c615cb63244b0c0"},"u_mu_service_type_c":"FixedFee","u_sales_stage":"Closed Lost","u_net_new_revenue_subtotal_ms_c":"0","u_services_resale_c":"false","u_cost_nms_c":"0","u_tprsb_profit_c":"0","u_mu_start_date_c":"","u_sales_stage_ps_c":"Closed Lost","u_commit_stage_tprm_c":"","u_cost_sps_c":"0","u_end_date_rs_c":"","u_upfront_total_ps_c":"0","u_uc_nsf_resale_cost_c":"0","u_subcontractor_cost_ps_c":"0","u_uc_hw_resale_profit_c":"0","u_type_ps_c":"TM","u_uc_nhw_resale_cost_c":"0","u_renewal_revenue_subtotal_ms_c":"0","u_profit_margin_cms_c":"0","u_tprsb_revenue_c":"0","u_tprh_revenue_c":"0","u_net_new_income_nms_c":"0","u_date_entered":"2018-03-21 22:20:55","u_revenue_cps_c":"0","u_uc_csn_resale_revenue_c":"0","u_actual_closed_date_tprh_c":"","u_uc_shw_resale_cost_c":"0","u_profit_margin_clms_c":"0","sys_updated_by":"Sugar2SvcNowSync","u_third_party_ps_revenue_c":"0","u_net_new_income_clms_c":"0","u_type_clps_c":"","u_uc_nsn_resale_revenue_c":"0","u_end_date_sr_c":"","u_hb_annual_profit_c":"0","u_special_instructions_text_rs_c":"","u_hb_annual_revenue_c":"0","u_professional_services_c":"true","u_end_date_tpr_c":"","u_hb_years_c":"1","u_actual_closed_date_tprsb_c":"","u_profit_tpr_c":"0","u_profit_cms_c":"0","u_revenue_nms_c":"0","u_setup_fee_sms_c":"0","u_lead_source":"","u_renewal_revenue_nms_c":"0","u_tprm_cost_c":"0","u_close_date_ps_c":"2018-06-30","u_third_party_ms_profit_c":"0","u_cost_clms_c":"0","u_term_sr_c":"","u_estimated_nps_revenue_c":"0","u_hb_expected_close_date_c":"","u_cost_sr_c":"0","u_tprsf_profit_c":"0","u_mu_end_date_c":"","u_actual_closed_date_ms_c":"","u_hb_hours_c":"0","u_hourly_block_c":"false","u_tprh_profit_c":"0","u_commit_stage_ms_c":"Funnel","u_uc_hw_resale_revenue_c":"0","u_mu_close_date_c":"1970-01-01","u_start_date_rs_c":"","u_profit_nps_c":"0","u_tprsf_cost_c":"0","u_uc_nsf_resale_profit_c":"0","u_uc_csb_resale_profit_c":"0","u_actual_closed_date_rs_c":"","u_commit_stage_rs_c":"Funnel","u_tprh_cost_c":"0","u_revenue_sms_c":"0","u_uc_nhw_resale_profit_c":"0","u_special_instructions_sr_c":"false","sys_mod_count":"1","u_uc_ssb_resale_revenue_c":"0","u_opportunity_name_base":"IVR UCCX Monthly Updates","u_renewal_revenue_sms_c":"0","u_setup_fees_subtotal_ms_c":"0","u_uc_csb_resale_revenue_c":"0","u_uc_nsb_resale_cost_c":"0","u_uc_csn_resale_cost_c":"0"}],""}

  • Hi Yury,

    Could you please attach the JSON Response file of your End Point from PostMan. So it will be more clear, I would like to see all the data and nested arrays in the response of the API End point. we can narrow down the issue very clearly.

  • To answer one of your questions - it shouldn't matter if the result key is an array or an object. Sugar's native APIs return a {"records":[]} which requires use of "records" as the rootKey.

  • Thank you Matt. This helps. Do you have any suggestions as to why I keep getting the "rootKey is required" error even after I added "result" as the response rootKey?

  • Hi Poojitha,

    I think I found the solution. The json response from Postman is too large to attach, but I noticed something that I missed earlier. At the end of the response there was an error message, so that the response looked like this:

    {

    "result":[{ }],

    "error": {
            "detail": "Transaction cancelled: maximum execution time exceeded Check logs for error trace or enable glide.rest.debug property to verify REST request processing",
            "message": "Transaction cancelled: maximum execution time exceeded"
        },
        "status": "failure"

    }

    The error messages were not included in the Vendor response in Integrate. This must be the reason why Integrate has not been able to parse the response. I deleted the /opportunity endpoint since I don't need to use it at this time. All the other endpoints work well. Thank you for your help!


  • Never mind, I think I figured out what the problem is. See my answer to Poojitha above.