Recent searches


No recent searches

Proxy error: UnprocessableEntity, Failed to get installation and oauth information for app



Posted Jan 20, 2022

I have been guided here by Zendesk support, I am receiving the error Proxy error: {:code=>"UnprocessableEntity", :status=>"422", :title=>"Unprocessable Entity", :message=>"Failed to get installation and oauth information for app."} when I attempt to create a request to a 3rd party server, I have followed your extensive guide but still recieving the above.


2

26

26 comments

image avatar

Eric Nelson

Zendesk Developer Advocacy

Hi Colin, 

Would you be able to provide us a link to your repository? This will help us to debug the issue more effectively. 

Thanks!

0


Hi, Please see below my Main.js and Iframe.html

Main.js

$(function() {
var client = ZAFClient.init();
client.invoke('resize', {
width: '100%',
height: '400px'
});
showForm();
$("#add-btn").click(function(event) {
event.preventDefault();
if ($("#subject").val().length < 0) {
client.invoke('notify', 'Subject can\'t be blank.', 'error');
} else {
var task = {
input_data: {
"request": {
subject: $("#subject").val(),
impact: $("#impact").val(),
Urgency: $("#urgency").val(),
subcategory: $("#subcategory").val(),
request_type: $("#request_type").val(),
mode: "zendesk"
}
}
};
sendTaskData(task, client);
}
});
});

function showForm() {
var source = $("#add_task-hdbs").html();
var template = Handlebars.compile(source);
var html = template();
$("#content").html(html);
}
var client = ZAFClient.init();
client.get('ticket.subject').then(function(subject) {
const sub = JSON.stringify(subject);
document.getElementById("subject").innerHTML = (sub.ticket.subject);
console.log(subject);
});

function sendTaskData(task, client) {
var settings = {
url: 'https://XXXX',
contentType: 'application/json;charset=utf-8',
headers: {
"Authorization": "Bearer XXXX",
"Accept": "application/vnd.manageengine.sdp.v3+json",
},
type: 'POST',
cors: false,
secure: true,
httpCompleteResponse: true,
data: JSON.stringify(task)
};
return client.request(settings).then((output) => {
const obj = JSON.parse(output);
document.getElementById("sdid").innerHTML = (obj.request.id);
console.log(output);
}).catch((error) => {
console.log("Error:", error);
});
}

Iframe.html

<!DOCTYPE html>
<html>
<head>
<link href="https://cdn.jsdelivr.net/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<link href="main.css" rel="stylesheet">
<title></title>
</head>
<body>
<div id="content"></div>
<script id="add_task-hdbs" type="text/x-handlebars-template">

<label for="Subject">Subject:</label>
<input type="text" name="subject" id="subject" maxlength="50" placeholder="Field for testing purposes">
<br>
<label for="impact">Impact:</label>
<select name="impact" id="impact">
<option value="low">Low</option>
<option value="medium">Medium</option>
<option value="high">High</option>
<option value="very high">Very High</option>
</select>
<br>
<label for="urgency">Urgency:</label>
<select name="urgency" id="urgency">
<option value="low">Low</option>
<option value="medium">Medium</option>
<option value="high">High</option>
<option value="very high">Very High</option>
</select>
<br>
<label for="subcategory">SubCategory:</label>
<select name="subcategory" id="subcategory">
<option value="Click Once">Click Once</option>
<option value="Comms">Comms</option>
<option value="Display and Resolution">Display and Resolution</option>
<option value="Enquiries API">Enquiries API</option>
<option value="Install">Install</option>
<option value="Licence">Licence</option>
<option value="Local Install">Local Install</option>
<option value="Network/ Connection">Network/ Connection </option>
<option value="Other Issue with Core">Other Issue </option>
<option value="Run A Script">Run A Script</option>
<option value="SMS">SMS</option>
<option value="Local Install">Local Install</option>
</select>
<label for="request_type">Request type:</label>
<select name="request_type" id="request_type">
<option value="Incident">Incident</option>
<option value="Service Request">Service Request</option>
<option value="Request For Information">Request For Information</option>
</select>
<br>
<label for="seviceDesk">ServiceDesk ID<div id="sdid"></div></label>
<!---<input type="text" name="servicedesk" id="servicedesk" maxlength="50" placeholder="" />-->
<br>
<div id="sdid"></div>
<Button id="add-btn" class="btn btn-primary btn-small">Create Request</button>
</form>
</script>
<script src="https://cdn.jsdelivr.net/jquery/3.0.0/jquery.min.js">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.min.js">
</script>
<script src="https://assets.zendesk.com/apps/sdk/2.0/zaf_sdk.js" type="text/javascript">
</script>
<script src="main.js" type="text/javascript">
</script>
<footer>
<a href="https://sdpondemand.manageengine.eu/" target="_blank">ServiceDesk</a>
</footer>
</body>
</html>

 

 

0


image avatar

Eric Nelson

Zendesk Developer Advocacy

Thanks for sending this over, a couple questions and notes:

1. I see that you have the secure flag listed in the settings. Are you inputting the bearer token as a secure param?

2. Are you encountering this issue when testing the application locally or when zipped and installed in your instance as a private app?

3. The specification of charset=utf-8 on the contentType is redundant as the default for json is utf-8.  

Thanks!

0


Hi,

1: I've tried with the secure setting in a param file and receive the same error.

2: I receive the error when testing locally, I received a 500 error when installed as a private app.

3: Noted regarding the content type, thank you.

 

 

0


image avatar

Eric Nelson

Zendesk Developer Advocacy

Hey Colin, 

Would you mind if I move this into a ticket so that you can share your code with us? 

Thanks!

0


Hi Eric, Certainly, thank you.

0


Hi,

I have the same issue, can you share with me the solution please?

is it ok to open a ticket to solve it?

thank you.

1


Hi,

I have the same issue, can you share with me the solution please?

is it ok to open a ticket to solve it?

thank you.

0


image avatar

Greg Katechis

Zendesk Developer Advocacy

Hi Pham! From my research, it appears that this may have been an issue with one of our integration services that has been resolved for a few weeks. Can you confirm that you are still experiencing this problem?

0


Hi I am receiving this error today in local dev mode I have added a secure token to my manifest like so 

 

```

"parameters": [
{
"name": "token",
"type": "text",
"secure": true
}
]

0


image avatar

Erica Girges

Zendesk Developer Advocacy

Hi Stuart,
 
If you're able to provide a link to the repo or code snippets that would be helpful for us to dig into it. It would also be greatly appreciated if you could provide context around when this error first began. Has it always been unsuccessful or have any known changes been made prior to it occurring? 
 
Looking forward to your response!
 
Best,
 
Erica

0


Hello,

I'm experiencing this issue in a Zendesk support app where I need to use a third-party API requiring HTTP Basic authentication. The issue is so far only locally and I've not yet tried to install the app. The following is code that makes the request:

    const metadata = await client.metadata();
  const apiUrl = metadata.settings.apiUrl;
  const settings = {
      url: 'https://' + apiUrl + '/' + path + (queryParams ? '?' + queryParams : ''),
      secure: true,
      cors: false,
      type: 'GET',
      dataType: 'json',
      contentType: 'application/json',
      headers: {
          Authorization: 'Basic {{setting.apiToken}}',
      },
      accepts: "application/json",
    };

  return client.request(settings)
      .then(successHandler)
        .catch(handleFailure);

And this is how my `menifet.json` look like:

{
  "name": "...",
  "author": {
      "name": "...",
      "email": "...",
      "url": "..."
  },
  "defaultLocale": "da",
  "private": true,
  "location": {
      "support": {
          "nav_bar": "assets/index.html"
      }
  },
  "version": "0.9.12",
  "frameworkVersion": "2.0",
  "domainWhitelist": ["{{setting.apiUrl}}"],
  "parameters": [
      {
          "name": "apiUrl",
          "type": "url",
          "required": true,
          "secure": false,
          "default": "..."
      },
      {
          "name": "apiToken",
          "type": "password",
          "required": true,
          "secure": true,
          "default": "..."
      }
  ]
}
This is not a new app. I'm changing the API endpoints in an existing app.
 
Best regards,
Ismail

0


Thank you for your answer Ahmed Zaid. That is very unfortunate. Do you know whether there is a way to find out whether the app is running locally? Knowing so will allow me to make an "insecure" request locally and use secure settings when it is not local.

0


For anyone having this issue. The following is working both locally and when installed:

    const metadata = await client.metadata();
  const apiUrl = metadata.settings.apiUrl;
  const settings = {
      url: 'https://' + apiUrl + '/' + path + (queryParams ? '?' + queryParams : ''),
      secure: !!metadata.installationId,
      cors: false,
      type: 'GET',
      dataType: 'json',
      contentType: 'application/json',
      headers: {
          Authorization: `Basic ${ !!metadata.installationId ? '{{setting.apiToken}}' : metadata.settings.apiToken }`,
      },
      accepts: "application/json",
  };
  return client.request(settings)
      .then(successHandler)
        .catch(handleFailure);

The `installationId` will be `0` when the app is running locally.

 

1


I was really hoping this would work. But when I fetch client.metadata I get a uuid installationId when I run locally

So based on further testing and investigating,

when local - the value is a string

when installed - the value is a number

so we can use a typeof check to work out if we are running locally or installed.

1


Very interesting Sal. Are you using zat or zcli? I'm using zat and here the installationId is 0 locally.

1


Hi I'm having a lot of problems with this too. In my manifest I have:

```

{

 "parameters": [
    {
      "name": "token",
      "type": "oauth"
    }
  ],
  "oauth": {
    "client_id": "XXX",
    "client_secret": "XXX",
    "authorize_uri": "https://XXX/oauth2/authorize",
    "access_token_uri": "https://XXX/oauth2/token",
    "scope": "email profile offline_access"
  }

}

```

and my code does

```

client.request({
  url: 'https://xxx.com/some/endpoint',
  type: 'GET',
  secure: true,
  headers: {Authorization: 'Bearer {{setting.token}}'},
})

```

The app seems to authorise fine when I go through the process but I still get this proxy error.

One detail is that I've installed the app in a zendesk sandbox to test it. Is this expected to work?

0


@Ismail - I am using ZCLI.

@Will I think you are missing secure: true for the parameter in the manifest file

0


If I set that I get

Uploading app... Uploaded
Deploying app... Failed
 ›   Error: Error: oauth parameter cannot be set to be secure.

0


image avatar

Eric Nelson

Zendesk Developer Advocacy

Hey Will,

You mind if we pull this into a ticket so that you can share a zip of your app for us to take a look at?

Thanks!

0


Eric, Will, did you guys ever find a solution to this? I am attempting the exact same thing and getting this issue. 

manifest.json

 "location": {
    "support": {
      "nav_bar": "assets/iframe.html"
    }
  },
  "parameters": [
    {
      "name": "access_token",
      "type": "oauth"
    }
  ],
  "oauth": {
    "client_id": "*********************************",
    "client_secret": "**********************************",
    "access_token_uri": "https://app.ninjarmm.com/oauth/token",
    "scopes": [
      "control monitoring management"
    ]
  },

bottom of iframe.html
  <script>
    // Initialise Apps framework client. See also:
    var client = ZAFClient.init();
    client.invoke('resize', { width: '100%', height: '200px' });
    async function getDevices() {
      const options = {
        type: "GET",
        headers: {
          Authorization: "Bearer {{setting.access_token}}",
        },
        secure: true,
      };
      await client.request(options).then((response) => {
        console.log(response.json());
      });
    }
    getDevices()
  </script>
 

0


image avatar

Tipene Hughes

Zendesk Developer Advocacy

Hey Parth,
 
Are you running this locally or is the app uploaded to your Zendesk instance?

0


Hi Tipene, uploaded to zendesk apps. I dont think i can run secure credentials locally. 

0


image avatar

Tipene Hughes

Zendesk Developer Advocacy

Thanks for the update. I'm going to pull this in to a private ticket so I can grab a few more details. You should see an email coming through from me shortly!

0


hello @Tipene Hughes sir 

const file = new File([blobData], mediaData.fileName, {
type: blobData.type,
});
const formData = new FormData();
formData.append("media", file);
formData.append("title", file.name);
formData.append("content_type", file.type);
formData.append("account", spokiAccount?.id);
const metadata = await client.metadata();

 
const sendMedia = await client.request({
url: `${BASE_URL}/media/`,
type: "POST",
dataType: "json",
data: formData,
headers: {
"Content-Type": "multipart/form-data",
X-secret:
typeof metadata.installationId === "string"
? spokiAccessKey
: "{{setting.spokiAccessKey}}",
},
secure: !(typeof metadata.installationId === "string"),
});


"hello Tipene Hughes sir When I pass FormData as the payload in my API call, the media file is not included in the payload when I check the request in the browser's network tab. Why is this happening, and how can I fix it? Also, can you confirm if my code is correct?"
 

 

0


image avatar

Greg Katechis

Zendesk Developer Advocacy

Hi Rocky! It's difficult to say exactly what problems you may be experiencing based on the code that you shared. I initially thought it may be due to the secure settings that you're using, but I don't think that's the case. Are you able to successfully send this to your service or even something like pastebin from a tool like Postman? It will help narrow down whether the issue is with the code or with the apps framework. Please share any other troubleshooting that you've done.

0


Please sign in to leave a comment.

Didn't find what you're looking for?

New post