Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodejs create_ticket_multiple_attachments.js does not work when trying to attach file #37

Open
blazejkroll opened this issue Aug 10, 2016 · 2 comments

Comments

@blazejkroll
Copy link

Seems like the
.attach('attachments[]', fs.createReadStream('/path/to/file1.ext'))
creates an error in my reqeuest. I got a 400 response with complains about some fields which are set:

{ description: 'Validation failed', errors:  [ { field: 'description', message: 'It should be a/an String', code: 'missing_field' }, { field: 'status', message: 'It should be one of these values: \'2,3,4,5,6,7\'', code: 'missing_field' }, { field: 'subject', message: 'It should be a/an String', code: 'missing_field' }, { field: 'priority', message: 'It should be one of these values: \'1,2,3,4\'', code: 'missing_field' }, { field: 'requester_id', message: 'Please fill at least 1 of requester_id, phone, email, twitter_id, facebook_id fields', code: 'missing_field' }, { field: 'type', message: 'It should be one of these values: \'Question,Problem,Feature Request,Praise,Complain\'', code: 'missing_field' } ] }

When I comment out all the .attach lines the ticket is created correctly. The files are present in the path.

My unirest request looks like this:

{
    "_stream": false,
    "_multipart": [
        {
            "name": "attachments[]",
            "value": {
                "_readableState": {
                    "objectMode": false,
                    "highWaterMark": 65536,
                    "buffer": [],
                    "length": 0,
                    "pipes": null,
                    "pipesCount": 0,
                    "flowing": null,
                    "ended": false,
                    "endEmitted": false,
                    "reading": false,
                    "sync": true,
                    "needReadable": false,
                    "emittedReadable": false,
                    "readableListening": false,
                    "defaultEncoding": "utf8",
                    "ranOut": false,
                    "awaitDrain": 0,
                    "readingMore": false,
                    "decoder": null,
                    "encoding": null
                },
                "readable": true,
                "domain": null,
                "_events": {},
                "_eventsCount": 1,
                "path": "/tmp/test0.png",
                "fd": null,
                "flags": "r",
                "mode": 438,
                "autoClose": true
            },
            "options": {
                "attachment": true
            },
            "attachment": true
        },
        {
            "name": "status",
            "value": "2",
            "options": {
                "attachment": false
            },
            "attachment": false
        },
        {
            "name": "priority",
            "value": "3",
            "options": {
                "attachment": false
            },
            "attachment": false
        },
        {
            "name": "type",
            "value": "Question",
            "options": {
                "attachment": false
            },
            "attachment": false
        },
        {
            "name": "email",
            "value": "[email protected]",
            "options": {
                "attachment": false
            },
            "attachment": false
        },
        {
            "name": "subject",
            "value": "Exemplary ticket subject",
            "options": {
                "attachment": false
            },
            "attachment": false
        },
        {
            "name": "description",
            "value": "test description",
            "options": {
                "attachment": false
            },
            "attachment": false
        },
        {
            "name": "custom_fields[platform]",
            "value": "test",
            "options": {
                "attachment": false
            },
            "attachment": false
        },
        {
            "name": "custom_fields[area]",
            "value": "test",
            "options": {
                "attachment": false
            },
            "attachment": false
        }
    ],
    "_form": [],
    "options": {
        "url": "https://<my_domian>.freshdesk.com/api/v2/tickets",
        "method": "post",
        "headers": {
            "Authorization": "Basic <my_auth>",
            "Content-Type": "multipart/form-data"
        }
    },
    "as": {}
}
@vicky-fd
Copy link
Contributor

Hi,
I hope you are using this sample to make an API request.

I tried the same sample and was able to make an API request. Can you provide your sample code?

@marcospada
Copy link

I get the same issue with PHP, attaching a file, with a custom header for 'Content-type: multipart/form-data' results in all ticket fields reported as missing, even though they're in the same data array as 'attachments[]'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants