Hi doers!
This will be a rather lengthy explanation of my problem, whose TLDR is: Uploading Files via API leads to URLs containing a “org/”, which seems to make it impossible to set them as attachment sources using the GraphQL API.
Here the full explanation:
I am trying to send E-Mails using Pipefy GraphQL API. In general, I do not have any problems with this. I can send E-Mails even with attachments. BUT: only if the attachments were uploaded manually. I am not able to do the attachment when using files uploaded via GraphQL API.
Step 1: Upload (works)
The upload works as described on this page:
First, I request the URL to upload to:
mutation {
createPresignedUrl(input: { organizationId: 123, fileName: "MyDocument.pdf" }){
clientMutationId
url
}
}
Then, I do the upload:
curl --request PUT
--url 'https://pipefy-production.s3-sa-east-1.amazonaws.com/orgs/ce63-a26b-412f-9d27-3a5776e16e/uploads/45da74d3-0e92-4e1c-a04e-2acc97169a3/SampleFile.pdf?...Signature=fa76e8bf28f88d8ceec1df8219912e103ad15f5ab4668f0fc9cea69109991aa'
--header 'Content-Type: application/pdf'
--data 'BINARY_DATA'
curl -v --upload-file SampleFile.pdf 'https://pipefy-production.s3-sa-east-1.amazonaws.com/orgs/ce63-a26b-412f-9d27-3a5776e16e/uploads/45da74d3-0e92-4e1c-a04e-2acc97169a3/SampleFile.pdf?...Signature=fa76e8bf28f88d8ceec1df8219912e103ad15f5ab4668f0fc9cea69109991aa'
Then, I assign the file to a card field:
mutation {
updateCardField(input: {card_id: 123, field_id: "attachment_field", new_value: v"orgs/8bd9ce63-a26b-412f-9d27-3a5776e3e16e/uploads/45da74d5-0e92-4e1c-a04e-26acc97169a3/SampleFile.pdf"]}) {
clientMutationId
success
}
}
At this point, I can view the attachment and download it without problems in Pipefy, indicating that this is the correct way to do it. No problems occur.
Step 2: Create E-Mail (works)
To create the E-Mail, I first fetch the URL again to make sure it did not change:
query {
card(id: 123) {
attachments { url createdAt }
}
}
Then, I use the url of the card to create the E-Mail:
mutation {
createInboxEmail(input: {
card_id: "123",
from: "pipe123@mail.pipefy.com",
subject: "TEST",
to: "test@genieblog.ch",
html: "Sehr geehrte Tim<br />
<br />
This is a Test",
emailAttachments: c{
fileUrl: "orgs/8bd9c63-a26b-412f-9d27-3a5776e3e16e/uploads/45da74d5-0e92-4e1c-a04e-26acc97169a3/File.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=BKIA6QQUS4NUNAO6IA%2F20180705%2Fsa-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180705T215845Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&x-amz-acl=public-read&X-Amz-Signature=fa76e8bf28f88d8ceec1df8219912e103ad15f5ab4668f0fc9cea69109991aa",
publicUrl: "https://pipefy-production.s3-sa-east-1.amazonaws.com/orgs/8bd9c63-a26b-412f-9d27-3a5776e3e16e/uploads/45da74d5-0e92-4e1c-a04e-26acc97169a3/File.pdf?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=BKIA6QQUS4NUNAO6IA%2F20180705%2Fsa-east-1%2Fs3%2Faws4_request&X-Amz-Date=20180705T215845Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&x-amz-acl=public-read&X-Amz-Signature=fa76e8bf28f88d8ceec1df8219912e103ad15f5ab4668f0fc9cea69109991aa",
fileName: "test.pdf"
}],
repo_id: "123"
}) {
inbox_email {
id
state
}
}
}
This too works without problems. I can go to Pipefy, open the card, look into the E-Mail as well as its attachments.
Step 3: Send E-Mail (does not work)
Finally, I use the returned inbox_email id to try to send the E-Mail:
mutation {
sendInboxEmail(input: {
id: "323876369"
}) {
clientMutationId
success
}
}
This is where it fails with the following Error:
{"data":{"sendInboxEmail":null},"errors":l{"message":"Invalid attachment files","locations":"{"line":3,"column":5}],"path"::"sendInboxEmail"],"code":30000,"type":"PipefyRuntimeError"}]}
What is the problem in my approach? What do I have to do differently? Why does the URL contain the “orgs/” part (which is not the case when uploading the file manually into Pipefy)?
Leaving the “orgs/” part away in either step 1 or 2 does not lead to files that could be opened, neither in the E-Mail nor the card, depending on where I make the change.