Unable to encode uri component

Viewed 18

I am trying to send encoded params as encoded uri component please view the code below:

params= {"requester":{"first_name": "hello@abc.com","email_id": "hello@abc.com", "login_user":"true"}};
    encodedpURL=encodeURIComponent(url+'?'+params);
    console.log(encodedpURL);
    const response = UrlFetchApp.fetch(encodedpURL, options);

The encodedURIComponent converts the url as

https%3A%2F%2Fhelpdesk.com%2Fapp%2Fitdesk%2Fapi%2Fv3%2Frequesters%3F%5Bobject%20Object%5D

The Use Case

  1. Send encoded query params to post data through API.

  2. Query Params: Key = input_data, Value = {"requester":{"first_name": "hello@abc.com","email_id": "hello@abc.com", "login_user":"true"}}

  3. The Value must be sent as Encoded URI Component.

  4. API Call

    var url = "https://helpdesk.com/app/itdesk/api/v3/requesters";
    var options = {
               "method": "post",
               "headers": {
                                "contentType": "application/x-www-form-urlencoded",  
                                "Accept": "application/vnd.manageengine.sdp.v3+json",            
                                "Authorization": "Zoho-oauthtoken "+apisheet[1][0]
                          },
    "muteHttpExceptions": true
              };`
    

Any reference of help will be highly appreciated. Thanks

0 Answers
Related