Postmark: Send email with template - node.js

I am trying to send a template email with Postmark in Node.js
I created a template on the Postmark App website. I've looked through their documentation, but cannot find any way to go about sending a templated email.
Documentation Sources:
http://blog.postmarkapp.com/post/125849089273/special-delivery-postmark-templates
http://developer.postmarkapp.com/developer-api-templates.html
I've tried a variety of methods, including:
client.emailWithTemplate("jenny#example.com",
"bob#example.com",<template-id>, {
"link" : "https://example.com/reset?key=secret",
"recipient_name" : "Jenny"
});
TypeError: Object # has no method 'emailWithTemplate'
client.sendEmail({
"TemplateModel" : {
"customer_name" : "Jenny",
},
"TemplateId" : 6882,
"From": "info#formulastocks.com",
"To": "lrroberts0122#gmail.com",
}, function(error, success) {
if(error) {
console.log(error);
} else {
console.log(success);
}
});
Console Log Error: { status: 422,
message: 'A \'TemplateId\' must not be used when sending a non-templated email.',
code: 1123 }
Thanks!

I'm the current maintainer of the node.js library (as well as one of the engineers that worked on Postmark Templates).
One of the possible reasons the original snippet doesn't work is that you could be using an older version of Postmark.js. We added the template endpoint capabilities in version 1.2.1 of the node.js package.
In the package.json file for your project you should make sure to update it to use version 1.2.1 or greater of the postmark.js library. If you've been using an older version of the library, you'll also need to run npm update
Also note that if you click "Edit Template" in the Postmark UI, and then "API Snippets," the UI provides a completed snippet for a number of languages (including node.js).
If all else fails, please contact support and we'll be happy to help you solve this issue.

Related

OpenSea 3.1 API Validation Errors

I believe OS's OpenApi definition is invalid at version v1.0#1e41yo45l0vihg6s. When I attempt to use it from Node using the api package in my project I get validation errors. Simple steps to reproduce:
Create a new Node project and initialize
mkdir os-api-test
cd os-api-test
npm init
Per OS docs/examples, install the api package:
npm install api --save
Create file index.js and populate it with the example code (address and API key omitted here, but they're valid and I can use them via the API UI):
const sdk = require('api')('#opensea/v1.0#1e41yo45l0vihg6s');
sdk['retrieving-a-single-contract']({
asset_contract_address: 'REDACTED',
'X-API-KEY': 'REDACTED'
})
.then(res => console.log(res))
.catch(err => console.error(err));
Run the example
node index.js
Output:
Looking at the API definition here and specifically at the /assets/get path, there are indeed duplicate owner parameters:
"parameters": [
{
"name": "owner",
"in": "query",
"description": "The address of the owner of the assets",
"schema": {
"type": "string"
}
},
...
{
"name": "owner",
"in": "query",
"schema": {
"type": "string"
}
}
...
And per the OpenApi 3.1 spec, in reference to the path item object:
A list of parameters that are applicable for all the operations described under this path. These parameters can be overridden at the operation level, but cannot be removed there. The list MUST NOT include duplicated parameters.
Obviously I can't change the API definition but is there any way to work around this, perhaps via configuration of the api package? I dug into its code but nothing jumped out at me. It's surprising that such a widely used API would have a bug that renders it unusable, yet I can't find any other mentions of it. I realize I may be able to use fetch to hit the API directly but I'd like to use the api package.
Interestingly the testnet API does not suffer from this same bug.
Thank you for surfacing this. We had documented the owner parameter twice, which led to this issue. It is fixed it now.

Why does Dialogflow nodejs sdk "detect Intent with Knowledge Base" method responds with null ? ( V2Beta)

I am integrating the Dialogflow Nodejs sdk into my application to detect the knowledge base intent with the help of the following document nodejs-dialoglowflow-detect-knowledgebase-intent.
Below is my query request
const request = {
session: sessionPath,
queryInput: {
text: {
// The query to send to the dialogflow agent
text: message,
// The language used by the client (en-US)
languageCode: 'en-US',
},
},
queryParams: {
knowledgeBaseNames: ['projects/my-project-id/knowledgeBases/my-knowledge-base-name'],
},
};
When I test the FAQ in dialogflow console it works, but when I try to do the same with Dialoglflow Nodejs SDK, the knowledgeAnswers object from dialogflow response is null.
Any help is appreciated. Thanks
This is happening because of the incorrect value in knowledgeBaseNames property.
When you create a knowledge base it returns below response:
{
"name": "projects/project-id/knowledgeBases/NDA4MTM4NzE2MjMwNDUxMjAwMA",
"displayName": "knowledge-base-display-name"
}
knowledgeBaseNames property accepts the array of name. It is different than displayName.
In case you have created the Konwledgebase form Dialogflow dashboard, you won't see this detail in the dashboard. However, Dialogflow SDKs Provide APIs to get the list of knowledgebase of an agent. Node js V2Beta1 SDK has a method projects.knowledgeBases.list, which, when given a project name, will list all of the knowledge bases along with their display name and their name. You can send the list of names into the detect intent request.
If your use case only requires knowing the ID for the knowledge base then you can get if from "Try it out" section of the Dialogflow console. Type a question you have added in knowledgebase and click on diagnostic info. It will show the dialogflow response in JSON. Look for the knowledgeAnswers object. The knowledgebase ID is the part of source property as mentioned below:
"knowledgeAnswers": {
"answers": [{
"source": "projects/project-id/knowledgeBases/knowledgebase-id/documents/document-id"
}]
}

Posting on facebook via unificationengine

Hi I'd like to post to facebook via unification engine. I've already created a user, added and tested successfully a facebook connection, but when I post I get the following response:
{"Status":{"facebook":{"status":190,"info":"Error validating access token: Session does not match current stored session. This may be because the user changed the password since the time the session was created or Facebook has changed the session for security reasons.: "}},"URIs":[]}
When I use the facebook token, that was used for creating the connection, to post to facebook directly (without unificationengine), then it works just fine. What might be the problem here? Status 190 is neither documented on facebook nor on unificationengine.
#unificatinengine developers: it would be practical, if the errors returned by the service would be passed on inside the unificationengine response, this way debugging such errors would be easier, and the errors could also be processed programmatically.
Additional info
Today I seem not to be able to reproduce the response of yesterday. The postfields I use to post the message to facebook (the same as yesterday) are as follows:
{
"message":{
"receivers":[
{
"name":"me",
"address":"https://graph.facebook.com/v2.1/me/feed",
"Connector":"facebook"
}
],
"sender":{
"address":"sender address"
},
"subject":"test",
"parts":[
{
"id":"0",
"contentType":"text/plain",
"type":"body",
"size":25,
"data":"this is the plain message"
},
{
"id":"1",
"contentType":"text/html",
"type":"body",
"size":42,
"data":"<div>this is the <b>html</b> message</div>"
},
{
"id":"2",
"contentType":"text/plain",
"type":"link",
"size":17,
"data":"http://www.web.de"
},
{
"id":"3",
"contentType":"text/plain",
"type":"link_description",
"size":21,
"data":"some link description"
},
{
"id":"4",
"contentType":"text/plain",
"type":"link_title",
"size":10,
"data":"link title"
}
]
}
}
But today I get the following message back from unificationengine
{
"Status":{
"facebook":{
"status":100,
"info":"Unsupported post request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api: "
}
},
"URIs":[]
}
Unfortunately this does not tell me, what unificationengine does internally for posting to facebook (which should not concern me), and what goes wrong there.
Does the "/v2/connection/info" show the details of the facebook connection that you have added? If not can you please update the connection with a new access token, using the same connection identifier for the "v2/connection/add" api endpoint, and check if it works.
unificationengine

Api version change but docs not updated?

I've been trying to do various things through your Mail REST API today and not having much success... My project (using the api) has been running for at least a month now, but requests to your api are failing.
For example:
GET https://outlook.office365.com/EWS/OData/Me/messages (works)
GET https://outlook.office365.com/EWS/OData/Me/inbox (doesn't work)
Looking at the documentation, still says its available.
Trying to send an email using:
POST https://outlook.office365.com/EWS/OData/Me/Messages?MessageDisposition=SendAndSaveCopy also just returns 400 (Bad Request)
Any info about this?
Also, the http status codes returned are not useful at all; almost all errors return as 400's. In one instance, I didn't provide auth creds, and a 400 was returned instead of the appropriate 401. The accompanying status code detail could also be more helpful.
Thanks for the feedback and sorry for the inconvenience. We are currently deploying some non-backwards compatible changes described here, and this is causing your issues. The current set of changes including versioning support, and deploying non-backwards compatible changes won't cause issues for your app in the future. For the queries, that don't work, please use the following:
Accessing Inbox: https://outlook.office365.com/ews/odata/me/folders/inbox
Send email (new action called SendMail):
POST https://outlook.office365.com/ews/odata/me/sendmail
{
"Message":
{
"Subject": "Test message",
"Body":
{
"Content": "This is test message!"
},
"ToRecipients":
[
{ "EmailAddress": { "Address": "John#contoso.com", "Name": "John Doe" }},
{ "EmailAddress": { "Address": "Jane#fabrikam.com", "Name": "Jane Smith" }}
]
},
"SaveToSentItems": true
}
Hope this helps. We are updating the documentation to reflect the changes, and it should be available shortly. Thanks for the feedback on the HTTP status codes, we will review the status codes returned currently and make any fixes required.
Conversation support is in our roadmap but we don't yet have a timeline to share. Currently, you can search using https://outlook.office365.com/ews/odata/Folders/FolderId/Messages?$filter=ConversationId%20eq%20%%27ConversationID%27 but this will only return messages within the specified folder belonging to that conversation.
Let me know if you have any questions or need more info.
Thanks,
Venkat

Paypal: Transaction History with REST API / Nodejs SDK

I would like to display all the inbound/outbound transactions a user made/received to display it in a simple html list.
I'm using the recommended node.js module https://github.com/paypal/rest-api-sdk-nodejs and I'm trying to use this code to get the transactions:
// Get Transaction History
paypal.payment.list({
'count': 100,
'sort_by':'create_time',
'sort_order': 'asc',
'start_time': '2008-03-06T11:00:00Z'
}, function(error, payment_history){
if(error){
console.error('error', error);
response.data.payment_history = {};
} else {
console.log('history', payment_history);
response.data.payment_history = payment_history;
}
response.finish();
});
but payment_history gives me { count: 0 }. I'm pretty sure that I have transactions since 2008.
I'm not really sure what's the problem. The user is already logged in using the access_token and I can display user informations but I have no idea how to pull transaction informations.
Look into https://developer.paypal.com/docs/faq/#general-developer-questions for the answer to "Can I retrieve the history of transactions created using the Classic APIs using the REST API?".
I also ran into this issue. Strangely, It seems that the PayPal REST API only returns results for payments made through the REST API. See here: https://stackoverflow.com/a/18139747
Classic API will remain the way to do this until the REST API is improved.

Resources