Zoho CRM API to Oower BI custom connector

Zoho CRM API to Oower BI custom connector

Hello everyone,

I've been struggling with this for a few days now , I hope I can get some help here.

I want to create a custom connector for Power BI that imports data from Zoho CRM.

Te OAuth 2.0 part of the code is working properly. The connector connects successfully to Zoho CRM but then it prompts this error: [DataFormatError] We couldn't parse your query string as it was improperly formatted

The code I'm using:

  1. // This file contains your Data Connector logic
  2. section Zoho_Connector___V1.1;

  3. // TODO: add your client id and secret to the embedded files

  4. client_id = "XXXXXX";

  5. client_secret = "XXXXXX";

  6. redirect_uri = "https://oauth.powerbi.com/views/oauthredirect.html";

  7. windowWidth = 800;

  8. windowHeight = 800;

  9. //Oauth base url for

  10. OAuthBaseUrl = "https://accounts.zoho.eu/oauth/v2/auth?";


  11. [DataSource.Kind="Zoho_Connector___V1.1", Publish="Zoho_Connector___V1.1.Publish"]
  12. shared Zoho_Connector___V1.1.Contents = () =>
  13. let

  14. navTable = Web.Contents("https://www.zohoapis.eu/crm/v2/Leads")

  15. in

  16. navTable;


  17. // Data Source Kind description
  18. Zoho_Connector___V1.1 = [
  19. Authentication = [
  20. // enable both OAuth and Key based auth

  21. OAuth = [

  22. StartLogin = StartLogin,

  23. FinishLogin = FinishLogin,

  24. Refresh=Refresh

  25. ]

  26. ],
  27. Label = Extension.LoadString("DataSourceLabel")
  28. ];

  29. // Data Source UI publishing description
  30. Zoho_Connector___V1.1.Publish = [
  31.     Beta = true,
  32.     Category = "Other",
  33.     ButtonText = { Extension.LoadString("ButtonTitle"), Extension.LoadString("ButtonHelp") },
  34.     LearnMoreUrl = "https://powerbi.microsoft.com/",
  35.     SourceImage = Zoho_Connector___V1.1.Icons,
  36.     SourceTypeImage = Zoho_Connector___V1.1.Icons
  37. ];

  38. // OAuth2 flow definition

  39. //


  40. // Start Login thorugh OAUTH
  41. StartLogin = (resourceUrl, state, display) =>

  42. let

  43. AuthorizeUrl = OAuthBaseUrl & Uri.BuildQueryString([

  44. scope = "ZohoCRM.modules.all",

  45. client_id = client_id,

  46. redirect_uri = redirect_uri,

  47. response_type = "code",

  48. state = state,

  49. access_type = "online"])

  50. in

  51. [

  52. LoginUri = AuthorizeUrl,

  53. CallbackUri = redirect_uri,

  54. WindowHeight = windowHeight,

  55. WindowWidth = windowWidth,

  56. Context = null

  57. ];

  58. // Finish Login through OAUTH

  59. FinishLogin = (context, callbackUri, state) =>

  60. let

  61. Parts = Uri.Parts(callbackUri)[Query]

  62. in

  63. TokenMethod(Parts[code], "authorization_code");



  64. TokenMethod = (code, grant_type) =>

  65. let

  66. Response = Web.Contents("https://accounts.zoho.eu/oauth/v2/token", [

  67. Content = Text.ToBinary(Uri.BuildQueryString([

  68. grant_type = "authorization_code",

  69. client_id = client_id,

  70. client_secret = client_secret,

  71. redirect_uri = redirect_uri,

  72. code = code
  73. ]
  74. )),

  75. Headers=[#"Content-type" = "application/x-www-form-urlencoded",#"Accept" = "application/json"]]),

  76. Parts = Json.Document(Response)

  77. in

  78. Parts;



  79. Refresh = (resourceUrl, refresh_token) => TokenMethod(refresh_token, "refresh_token");


  80. Zoho_Connector___V1.1.Icons = [
  81.     Icon16 = { Extension.Contents("Zoho_Connector___V1.116.png"), Extension.Contents("Zoho_Connector___V1.120.png"), Extension.Contents("Zoho_Connector___V1.124.png"), Extension.Contents("Zoho_Connector___V1.132.png") },
  82.     Icon32 = { Extension.Contents("Zoho_Connector___V1.132.png"), Extension.Contents("Zoho_Connector___V1.140.png"), Extension.Contents("Zoho_Connector___V1.148.png"), Extension.Contents("Zoho_Connector___V1.164.png") }
  83. ];

Any ideas about what I'm doing wrong?

Thanks