Hello! I didn't find a solution in the existing entries, so here is my question.

I'm using this code to create a new ticket, everything is OK except the attachment:
{
"alert": true,
"autorespond": true,
"source": "API",
"topicId": 1,
"name": "User Name",
"email": "user@noemail.com",
"subject": "Testing API",
"phone": "1122334455",
"acta": "1122334455",
"jurisdiccion": "CABA",
"dominio": "lnm632",
"dni": "33116561",
"message": "data:text/plain,Testing API",
"ip": "172.233.25.113",
"attachments": [
{
"/media/gravity_forms/4-a4aa02275944c3bb108bc634424515aa/2024/06/Colecta-2024_12.png": "data:text/plain;charset=utf-8,content of attachment"
}
]
}

The field where it is supposed to be uploaded is empty.
But there is a link with no file:

The name of this link is the current location of the uploaded file in other place, and this links to: mydomain.com/file.php?key=fnf8dvmzuklu-4_tg8s7gvwtuunrlc3o&expires=1718323200&signature=5d3385a87b0849327e2ef13b7dbea85522e90b29&id=27

Which downloads an empty file.

  • KevinTheJedi replied to this.
  • apipostman

    Attachments don’t work like that. If you want a link to a file hosted externally then you must include the link within the body. If you want to attach (upload) the actual file and contents then you must download the file and put the raw contents within the JSON payload as shown in the documentation.

    Also, if you want to add a link to an external file to a custom field you must pass that as a string value with the custom field’s Variable name as the key in the JSON payload. If you want to upload the actual file and contents do the same as I mentioned in the above paragraph however the key will be the custom field’s Variable name.

    P.S.
    If you are using PHP to generate the JSON payload you can use something like PHP’s native file_get_contents() function to get the file’s raw contents.

    Cheers.

    apipostman

    Attachments don’t work like that. If you want a link to a file hosted externally then you must include the link within the body. If you want to attach (upload) the actual file and contents then you must download the file and put the raw contents within the JSON payload as shown in the documentation.

    Also, if you want to add a link to an external file to a custom field you must pass that as a string value with the custom field’s Variable name as the key in the JSON payload. If you want to upload the actual file and contents do the same as I mentioned in the above paragraph however the key will be the custom field’s Variable name.

    P.S.
    If you are using PHP to generate the JSON payload you can use something like PHP’s native file_get_contents() function to get the file’s raw contents.

    Cheers.

    Thanks for the quick reply. I wasn't able to find this doc, can you please send me the link?

    Is it possible to ask you about another issue? Or should I open another ticket?
    Basically when I try to edit the user template, when I hit the save button it keeps "saving", but it never saves.

    Hi Kevin! I was digging a bit mor and I found a post of you where you mention the correct format of the JSON, example. I uploaded the demo image here: https://www.base64-image.de/ and put the code in the last part of the json but this wont work, Im not getting the ticket created!

    "infraccion-pdf": [
    {
    "image.png":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA+cAAAHuCAYAAAGKaU3LAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAABl9BJREFUeNrsmnlUFEcex79zMeN6LfqIRrOJUaMGj+VFN+tBFlgjw8vqumbi9fCIGkW8I65HNIo8NSbeJoCKERQxEAIqEGDxgKjoilG5LxEHZHCGAYYRBnrO3uoeYH378ocYNSzU572e6umq/nV1fevX9fvNNEChUCgUCoVCoVAoFAqFQqFQKJQXiOAF2GT5D5bF8OHDkZeXR0f5txSY8MJFZzm1Ke1adCEdls4HFZ2KTukMiJ+3wTnH85+q3elPnFv3S+sYCMxWvOnUFYUllXj1jT6wqXOhxasoqqvCAFFXjHR+E9W6JtQ1meDk1A3dxFawBj3H9fot4ofesHgPbqg0gfXwWVi07oYp9fVzfthTVGjZAYQ5wSNsGeflWaNe3B/q51UKVBvZo3cQB8VO6Yuyee3gUvgRLE5qjBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQQQgghhBBCCCGEEEIIIYQQQgghhBBCCCGEEM/w/wAGX9BlkhCpNQAAAABJRU5ErkJggg=="
    }
    ]

    PS: on the example I removed characters because of the character limitation in the post.
    PS2: using "attachments": [ this code works and I can see the uploaded image in the notes, but I want to load this in the custom field "infracciones-pdf"

      apipostman

      Here is the API Documentation:

      To upload files to custom fields you should be able to just use the Variable name of the field as the key and then format the data exactly as you would the regular attachments.

      As far as the template issue you’ll need to look at your web server error logs and PHP error logs for a related error.

      Cheers.

      Thanks Kevin! I believe I'm following your instructions, but the ticket is not created:

      {
      "alert": true,
      "autorespond": true,
      "source": "API",
      "name": "Angry User",
      "email": "api@osticket.com",
      "phone": "3185558634X123",
      "subject": "Testing API",
      "ip": "123.211.233.122",
      "message": "data:text/html,MESSAGE <b>HERE</b>",
      "infraccion-pdf": [
      {"image.png": "data:image/png;base64,R0lGODdhMAA..."},
      ]
      }

      Its gibing me 500 internal error:

      thanks

        apipostman

        Remove the trailing comma at the end of the attachment object. Also, check your error logs for any related errors.

        Cheers.

          apipostman

          Where was the field added? What form? Is that form attached to the help topic you are setting in the API request?

          Cheers.

          Kevin, first of all thank you so much for the support.

          This is the form with the custom field "infraccion-pdf"

          This is the help topic with ID 1:



          and here the help topic with the form:

          Anything else that could help understand this?

          apipostman

          You need to add "topicId": 1, to your JSON payload or set that help topic as the default help topic in your system settings.

          Cheers.

          apipostman

          Idk then, I’ll have to test on Monday to see. It’s basically saying that field isn’t available with the options you provided. So it’s likely disabled somewhere or not attached to the help topic or something.

          Cheers.

            9 days later
            Write a Reply...