Third-party API request with Zendesk Proxy Server: 'grant_type': 'client_credentials' doesn't work. | Community
Skip to main content

Third-party API request with Zendesk Proxy Server: 'grant_type': 'client_credentials' doesn't work.

  • April 1, 2023
  • 4 replies
  • 0 views

I'm testing Zendesk Proxy Server to make an request to a third-party API. My original JavaScript code use fetch() for making request. Here how it is,

fetch(`${tokenUrl}/token`, {

        method: 'POST',

        body: new URLSearchParams({

            'grant_type': 'client_credentials'

        }),

        headers: {

            'Content-type': 'application/x-www-form-urlencoded',

            'Authorization': `Basic ${basic_token}`

           

        },

    }).then((response) => response.json())

    .then((data) => {

       // my working code;

})
Here is my curl request:
 
curl -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Basic basic_token" -X POST "url_to_request" -d "grant_type=client_credentials"
 
Both fetch() and curl requests are working fine, but when I try to make request with Zendesk proxy server, I got some error and the request is unsuccessful. Here is how I write:
 
const client = ZAFClient.init();
const options = {

                url: `${tokenUrl}/token`,

                type: 'POST',

                secure : true,

                contentType: 'application/x-www-form-urlencoded',

                headers: {

                    "Authorization": `Basic ${basic_token}`

                },

                data: new URLSearchParams({

                    'grant_type': 'client_credentials'

                }),

              };



client.request(options).then((response) => {

         console.log(response);

});
 
The browser console show the error as below:
 
Please guide me how I can solve this issue.

4 replies

Greg29
  • April 3, 2023

Hi Su! It looks like you have an open ticket where my colleague requested the zipped app. I've cc'd myself on that ticket, so could you update that ticket with the app and then I can take a look at it for you?


  • Author
  • April 4, 2023

Hi Greg,

This is my separate ticket for another different issue. How could I convert 'grant_type': 'client_credentials' in ZAF client request?  Please guide me for the solution.

 

For the ticket you mentioned, I have sent the zipped file and waiting for the reply some days ago and still no reply yet. I will send again and please check the mail. Thank you.


Greg29
  • April 10, 2023
Apologies for my confusion there...in this situation, are you installing this app directly in your account or are you running this locally with zcli? If you are running this locally, the secure settings will not work, as we outline here. If this is installed in your instance, let me know and we can continue troubleshooting that.
 
As a separate update, I still have not seen any response with the zipped application in the other ticket. Could you send a comment update in there just to make sure we're receiving anything from you there?

  • Author
  • April 18, 2023

Hi Greg,

Yes, I installed the app in my account. The app is add_todoist_tasks and you can find my issue in this ticket,

https://support.zendesk.com/hc/en-us/community/posts/5515389135898-I-can-t-run-the-app-successfully-422-error-message

The followings are the mails I have sent. Kindly check. I send it again for today.

 

 

Also, please check this ticket for my question, 'How could I convert 'grant_type': 'client_credentials' in ZAF client request?' . I have two tickets in total and still no solution yet. Thanks.