Contact search api is not working

Hi @Jyoti ,

From your screenshot I can understand you’re trying to use Basic Authentication with Api key to call freshdesk API. There are few mistakes in your code to be corrected. Let me point out those & also I’m sharing a sample working zip for your reference.

Note: The end point you’re trying to use works different - it’s used to get a list of contacts matching the specified contact fields specified in the query. More details - Freshdesk

  • In the header, the value for “Authorization” must be “Basic APIkey:X” where APIkey:X must be Base64-
    encoded. Please use this tool to encode it: https://www.base64encode.org/
    E.g. if your API key is WestY134, then you must encode WestY134:X to
    base64, resulting in something like: “OUpKSGg6WA==”. Then you can pass the same in header

Note: Instead you can chose to get from iparams like <%= iparam.key %>

Attaching the working zip also for your reference.
Note: Make sure to replace your encoded api key & hardcoded searchKey accordingly.

contact-search-test.zip (4.5 KB)

Hope this helps! Thanks.

Hi
Please send me the zip file again.

Hi
I am getting the same error again after following the instructions you gave to me.

Please send me the zip file again.

contact-search-test.zip (4.5 KB)

I am getting the same error again after following the instructions you gave to me.

Make sure, you’re trying to use client.request.get only after the app is initialised & activated. Please follow our request method sample app code for more details - request-method-samples/freshdesk at platform-2.3 · freshworks-developers/request-method-samples · GitHub

Also try running the zip shared above & understand the flow. You should be able to replicate it for your usecase. As you’ve not shared your actual code snippets, I not able to predict your other parts of the application.

Thanks

Hi

I did the same as you gave instructions to me. However, I am getting the same thing. Below is the screenshot. Please give me a solution and also send me your number if possible.

Hi
Please contact me related to my issue.

Did you try running this zip with your api key? Is it working fine?

I guess you’re executing the script before app initialized & activated. Where is your app.js script included? Make sure this script block is executed after that or better move this logic to app.js itself.

Screenshots doesn’t seem to help much, most of your code blocks are hidden. Please try the above zip or share us the app zip to help better.

Thanks

Hi
The zip file you are sending not extracting.
Mcube (4).zip (79.7 KB)

Hi

As per our conversation, I sent you the zip of my project. Please look into this and provide me the resolution.

That’s a simple valid zip & shouldn’t be any problem with extraction. Please check & try again.

Let me check and get back to you.

Thanks

Hi @Jyoti ,

On checking your zip, I can see still the way you encoded your API key is not as I mentioned above. I guess, if you manage to unzip & check the demo app shared above things should be more clear to you. Anyway, I’m sharing the detail below hiding the sensitive information (please make sure to replace it with actual value accordingly)

This is your current code,

var search = $('#searchKey').val();
            var headers = {
                "Authorization": "encoded_key",
                "Content-Type": "application/json"
            };

But, what is expected is

const searchKey = 'Andy from google' // hardcoded, please replace this with your actual DOM value
  const headers = {
    //     In the header, the value for “Authorization” must be “Basic APIkey:X” where APIkey:X must be Base64-encoded.
    // E.g. if your API key is W25uOtAmhj8V8zT9JJHh, then you must encode W25uOtAmhj8V8zT9JJHh:X to base64, resulting in: “VzI1dU90QW1oajhWOHpUOUpKSGg6WA==”. Then you pass in the header:

    // Authorization: Basic VzI1dU90QW1oajhWOHpUOUpKSGg6WA==

    // You can use this tool to encode it: https://www.base64encode.org/
    "Authorization": 'Basic <Your Encoded key here>', // your encoded api key here
    "Content-Type": "application/json",
  }     

Again requesting you to extract the sample zip shared above (or) look at our sample apps bucket to make this easier.

Hope this helps. Thanks