最近搜索


没有最近搜索

是否可以使用 API 将文件附加到工单?



已于 2025年4月03日 编辑


-1

0

27 条评论

The change to 60 minutes for token expiration is very unwelcome.  Please return to the 3 day token expiration window that was previously in place.  It used to be possible to safely prepare and execute the Tickets Bulk Import endpoint to efficiently run thousands of tickets.  This change pushes me to need to now consider running each ticket import individually, doing a just-in-time upload of the files needed for the comments in ticket.  

0


que instrução vazia.

Pq a zendesk tem dificuldade de orientar o básico de como fazer? 

0


Hi Paolo

Thx for the reply.

Did make the suggested api calls using postman to get data for the attachment.

However, it does look very similair to the data returned from the endpoint: tickets/${ticket.id}/comments. The data returned from this call  was added to the tickets object before bulk import it. 
This creates a ticket with comments, but the attachment does not follow with.

Am i right to assume that if I use the Incremental Ticket Event Export, I can use this data to add both comments and attachment when doing the bulk import using the endpoint; imports/tickets/create_many

Thx again, Albin

 

0


Hi Albin,
 
If you are trying to get the ticket attachments, you may use the Incremental Ticket Event Export. Sample: GET /api/v2/incremental/ticket_events.json?include=comment_events,attachments,tickets,agreements&start_time={epoch_time}.

1


Hi all

How would this work if I am planning to do a Bulk Import with the endpoint tickets/create_many?
https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_import/.

Do use this endpoint as I get the tickets metric, am able to get the comments for the tickets, but the attachments does not come with.

This is my code:

async function getComments(ticketData) {

  for (let i = 0; i < ticketData.length; i++) {

    const ticket = ticketData[i];

    try {

      const response = await axios({

        method: 'GET',

        url: `${process.env.albinURL}/tickets/${ticket.id}/comments`,

        headers: {

          'Content-Type': 'application/json',

          Authorization: `${process.env.albinAuth}`,

        },

      });

      // Add comments to the ticket

      ticket.comments = response.data.comments;

    } catch (error) {

      console.error(`Error fetching comments for ticket ${ticket.id}:`, error);

    }

  }
}
async function createTicket(data) {

  console.log('CREATING TICKETS');

  var config = {

    method: 'POST',

    url: `${process.env.albinURL}/imports/tickets/create_many`,

    headers: {

      'Content-Type': 'application/json',

      Authorization: `${process.env.albinAuth}`,

    },

    data: data,

  };

  try {

    const response = await axios(config);

    console.log('CREATED');

    console.log(response);

    console.log(response.status);

    return response.status === 200;

  } catch (error) {

    console.log(error.response.data);

    console.log('ERROR');

    return false;

  }

}
, Albin

0


Hello Mahendran,
 
You can achieve it using 2 steps:
 
1. POST /api/v2/uploads 
Use this Attachment API endpoint for uploading your file. 
Curl sample: 
curl "https://{subdomain}.zendesk.com/api/v2/uploads?filename=user_crash.log&token={optional_token}"
Payload example:
{
"upload": {
"token": "abc123...",
...
}
}
 
2. PUT /api/v2/tickets/{ticket_id}
Use this Ticket API endpoint for updating your ticket. 
Example payload
{
"ticket": {
"subject": "My Subject",
"comment": {
"body": "A comment with an attachment",
"uploads": ["abc123..."]
}
}
}
Please notice
- please replace your data accordingly
- the token is valid for 3 days,
- make sure to include the right content type in the headers. For example: "image/png", "text/plain", "multipart/form-data", "application/json" etc. 

Hope it helps

0


Hi,
I want to upload the attachment for the respective ticket. Is it possible in ticket import API?
Thanks,

0


Hi Marcus,
 
The token value itself may be invalid for some reason.  To test this, can you successfully create/update the ticket with an empty uploads array?
 
{

  "ticket": {

   "comment":  { "body": "See PDF.", "uploads":  [] }

  }

0


Hello,

With the example from above and the current attachment token I always get the following error message back:

{
    "error": "RecordInvalid",
    "description": "Record validation errors",
    "details": {
        "base": [
            {
              "description": "Uploads is invalid"
            }
        ]
    }
}

API Request:

{
 "ticket": {
   "comment":  { "body": "See PDF.", "uploads":  ["i2duiFM7GNcgJxo48HJWJFoA1"] }
 }
}

 

Any recommondations or advices ?

 

Thanks !

Best regards,

Marcus

0


Hey folks! Based on the questions being asked, I wanted to make sure you were aware of our Developer Support team. They have more in-depth knowledge of our platform tools and will be able to get you the best possible answers and solutions. This team works out of our Developer Support community, which will also give you the opportunity to have other developers to share their insight as well! To get in touch, please go to the community and include as much relevant information in your post as you feel comfortable sharing. 

0


请先登录再写评论。