Error when getting a token to impersonate a user to open a request on their behalf | Community
Skip to main content

Error when getting a token to impersonate a user to open a request on their behalf

  • December 7, 2021
  • 4 replies
  • 0 views

Jeb

Here is the issue we are having. We are trying to get a token to impersonate a user to open a request on their behalf. From what we understand we need to call:

https://thiswayglobal.zendesk.com/api/v2/oauth/tokens.json

with this body:

{

"token":{

"client_id": "my_company_name",

"scopes": "impersonate"

}

}

We are using Basic Auth with the admin email and the API token as the password. Also the Content-Type is "application/json".

When we submit we get a 400 Bad Request with the following message:

{

"error": {

"title": "Invalid attribute",

"message": "You passed an invalid value for the token.client_id attribute. Invalid parameter: token.client_id must be an integer from zendesk/o_auth/api/v2/tokens/create"

}

}

Can you explain what is going on?

4 replies

Greg29
  • December 8, 2021

Hi Jeb! In the payload that you shared, it's look like you're passing in a string instead of an integer. You can take a look at our reference docs on creating this token to grab that integer and then you'll pass that in the payload instead of a string.


Jeb
  • Author
  • December 9, 2021

So thank you for the quick response. That resolved my question. I can now get the new token and using it but I now have another follow up :)

So I am trying to open a new ticket on behalf of a user. When I make the call as myself it works fine. But when I a new request on behalf of them it is giving me an error.

For example:

{
"request": {
"subject": "Help!",
"comment": {
"body": "My printer is on fire!",
"type": "Incident"
},
"priority": "normal",
"type": "incident",
"status": "open"
}
}

Works fine for opening my own ticket. When I add the following to the header:

"X-On-Behalf-Of","tomjones.example.com"

I get the following error:

{
"error": "RecordInvalid",
"description": "Record validation errors",
"details": {
"base": [ { "description": "Type: cannot be blank",
"error": "BlankValue",
"field_key": 360040711652 } ] } }

I am also using auth of 'Bearer Token' with the new token I created in the earlier steps. Also, the user I am making the request on behalf of is not a user in Zendesk. Thanks in advance


Greg29
  • December 9, 2021

Glad that first bit worked for you! In the error response, it's saying that there is a ticket field that is required when submitting a ticket and that isn't included in your payload. It's likely that the ticket field is required for end-users on ticket submission, but not agents or admins, which is why your example may have worked. It's also possible that this is a newly added requirement. Just navigate to that ticket field in your agent interface to confirm if that is indeed the case!


Jeb
  • Author
  • December 9, 2021

Since the first issue was resolved, I am going to open a new ticket with my second issue. That way if someone else has an issue, they can see how we resolve it. You can mark this answered.