Can't get substitutions working with SendGrid's API V3 - sendgrid-api-v3

I am successfully sending emails using SendGrids Web API v3 but can't get the subsitutions to work when sending emails using templates. The emails come through successfully but no substitutions take place. Here is my (simplified) SendGrid template:
<html>
<head>
<title></title>
</head>
<body>
<div>You can reset your password by clicking on this link: {callbackUrl}</div>
<%body%>
</body>
</html>
And here is the JSON formatted body I'm sending:
{
"personalizations":[
{
"to":[
{
"email":"destinationemail#gmail.com"
}
]
}
],
"sub" : {
"{callbackUrl}" : "www.mysite.com/changepassword"
},
"from":{
"email":"example#example.com"
},
"template_id" :"5f852a2e-996b-4f04-be05-31766d1092d8",
"subject":"Reset your password",
"content":
[
{"type": "text/plain", "value": "Thank you"}]
}
The email is generated with the correct template, subject, and is sent to the correct email address however the email body contains the template without substitutions:
You can reset your password by clicking on this link: {callbackUrl}
Thank you
I'm at a loss as to what I'm doing wrong. I'm using currently using Postman to send the request while attempting to track down the issue.

You need to use key substitutions under personalizations, not sub as it's said in the docs. Also it has different structure than sub.
{
"personalizations" : [ {
"substitutions" : {
":name" : "John"
},
"subject" : "Hello from Java",
"to" : [ {
"email" : "john#example.com"
} ]
} ],
"from" : {
"email" : "john#example.com"
},
"template_id" : "11111111-1111-1111-1111-111111111111"
}

Related

How to create an Azure Search indexer using the REST API

Due to a bug in the Azure portal, I am needing to create an Azure Cognitive Search data source, index, and indexer programmatically using the REST API. There were no issues creating the data source or index, but the POST request below returns the following error.
{
"error": {
"code": "",
"message": "The request is invalid. Details: dataSource : A resource without a type name was found, but no expected type was specified. To allow entries without type information, the expected type must also be specified when the model is specified.\r\n"
}
}
The following POST request is a modified example found on this page, with the variables replaced with the correct names of the service-name, admin-key, dataSourceName and targetIndexName.
POST request (using postman)
POST https://SERVICENAME.search.windows.net/indexers?api-version=2019-05-06
Content-Type: application/json
api-key: ADMINKEY
{
"name" : "my-json-indexer",
"dataSourceName" : "BLOBDATASOURCE",
"targetIndexName" : "TARGETINDEX",
"schedule" : { "interval" : "PT2H" },
"parameters" : { "configuration" : { "parsingMode" : "json" } }
}
Seems that when you've created your data source, the type property was not provided.
Here's the two requests:
Create data source
POST https://[service name].search.windows.net/datasources?api-version=2019-05-06
Content-Type: application/json
api-key: [admin key for Azure Cognitive Search]
{
"name" : "my-blob-datasource",
"type" : "azureblob",
"credentials" : { "connectionString" : "DefaultEndpointsProtocol=https;AccountName=<account name>;AccountKey=<account key>;" },
"container" : { "name" : "my-container", "query" : "optional, my-folder" }
}
Create indexer
POST https://[service name].search.windows.net/indexers?api-version=2019-05-06
Content-Type: application/json
api-key: [admin key for Azure Cognitive Search]
{
"name" : "my-json-indexer",
"dataSourceName" : "my-blob-datasource",
"targetIndexName" : "my-target-index",
"schedule" : { "interval" : "PT2H" },
"parameters" : { "configuration" : { "parsingMode" : "json" } },
"fieldMappings" : [
{ "sourceFieldName" : "/article/text", "targetFieldName" : "text" },
{ "sourceFieldName" : "/article/datePublished", "targetFieldName" : "date" },
{ "sourceFieldName" : "/article/tags", "targetFieldName" : "tags" }
]
}

Firebase Cloud Firestore - Fail to write via REST API

This is not an authentication error, write is enabled on the database rules.
My cloud Firestore database looks like the picture below.
There is a COLLECTION called colA, inside it there is a DOCUMENT called docA, and inside it there are some fields (strings) stored.
On Postman, if I do GET https://firestore.googleapis.com/v1/projects/eletronica-ab6b1/databases/(default)/documents/colA/docA, I do receive the following answer, and it is correct:
{
"name": "projects/eletronica-ab6b1/databases/(default)/documents/colA/docA",
"fields": {
"fieldB": {
"stringValue": "ABCD"
},
"fieldA": {
"stringValue": "888"
}
},
"createTime": "2020-01-31T16:48:26.859181Z",
"updateTime": "2020-02-05T19:21:49.654340Z"
}
Now, when I try to write a new field (fieldC) via POST https://firestore.googleapis.com/v1/projects/eletronica-ab6b1/databases/(default)/documents/colA/docA, with JSON content:
{
"name": "projects/eletronica-ab6b1/databases/(default)/documents/colA/docA",
"fields": {
"fieldC": {
"stringValue": "1000"
}
}
}
After SEND, I receive this:
{
"error": {
"code": 400,
"message": "Document parent name \"projects/eletronica-ab6b1/databases/(default)/documents/colA\" lacks \"/\" at index 60.",
"status": "INVALID_ARGUMENT"
}
}
What I'm doing wrong? I really would like to write strings there via REST API.
Regards.
Updating a document is done with a PATCH request, according to the [reference documentation).
A POST request is used to create a new document in a collection, which probably explains the error you get: you're pointing to a document, but POST expects a collection path.

Cannot query ACF Options page with GraphQL and GatsbyJS

I am trying to query my ACF options page fields that I have set up in the admin side, and through the WP API Query them using GatsbyJS's gatsby-source-wordpress. When I run build and dev it requests the data and prints out the output
=== [ Fetching wordpress__acf_options ] === http://url.local/wp-json/acf/v3/options/options/
⠈ source and transform nodes -> wordpress__acf_options fetched : 1
Fetching the wordpress__acf_options took: 518.885ms
=== [ Fetching wordpress__acf_options ] === http://url.local/wp-json/acf/v3/options/options
⠈ source and transform nodes -> wordpress__acf_options fetched : 1
Fetching the wordpress__acf_options took: 478.580ms
and within those urls on the browser, I get this response. So I know the data is correct
{
acf: {
social_options: [
{
social_name: "Twitter ",
social_link: "https://twitter.com"
},
{
social_name: "Linkedin",
social_link: "https://www.linkedin.com/"
}
],
test: "pagfe 1"
}
}
The problem is when I query the allWordpressAcfOptions in the internal GraphQL. I try and see what options are available to query but all I can get is the ID. This is my query below.
{
allWordpressAcfOptions {
edges {
node {
id
internal {
type
contentDigest
owner
}
children {
id
}
wordpress_id
}
}
}
}
and none of the data in there is the data I need, an none of it is representative of the same data shown from REST API Link. So there is something missing. This is the response I get back from the Query.
{
"data": {
"allWordpressAcfOptions": {
"edges": [
{
"node": {
"id": "038ece9f-326d-5bb0-8f17-1bb72ce06c57",
"internal": {
"type": "wordpress__acf_options",
"contentDigest": "10b2729a5f87723bbafc539f99fb23d6",
"owner": "gatsby-source-wordpress"
},
"children": [],
"wordpress_id": "acf"
}
}
]
}
}
}
For reference my gatsby-source-wordpress options in the gatsby config are this below
options: {
baseUrl: 'url.local',
protocol: 'http',
hostingWPCOM: false,
useACF: true,
acfOptionPageIds: ['options'],
verboseOutput: true
},
options refers to the page ID the my ACF options page is set in my functions.php on the wordpress side.
So in summary, GatsbyJs is referencing the API and pulling the data but what am I doing wrong to query the data via GraphQL?

Access fileObj storeName or key collectionFS

How can I get in a call back after inserting a file using collectionFS the key value?
Images.insert(file, function (err, fileObj) {
if (err) {
console.log(err);
} else {
console.log('success', fileObj);
setTimeout(function () {
console.log('url', fileObj.url());
let url = fileObj.url('images');
$scope.slideshows.url = `${url}`
$scope.$apply();
}, 2000);
}
});
I'm building a cms which handles file uploads to show in different apps, I'm able to see the uploaded file using {{image.url}} in the cms but I'm unable to view the images uploaded using this method in the other apps.
Every app is connecting to the same database and I'm uploading the images into my server using:
Images = new FS.Collection("images", {
stores: [new FS.Store.FileSystem("images", {path: '/home/uploadedimages'})]
});
I'm then using nginx to serve those images so I can access them via http://domain.com/uploadedimages.
In order to fix my problem I need to somehow get the key value in this schema stored by collectionFS:
{
"_id" : "5BEe4maLCMFtHAZAj",
"original" : {
"name" : "wantedposter.jpg",
"updatedAt" : ISODate("2016-05-19T13:34:32.050Z"),
"size" : 28828,
"type" : "image/jpeg"
},
"uploadedAt" : ISODate("2016-05-19T21:30:54.299Z"),
"copies" : {
"images" : {
"name" : "wantedposter.jpg",
"type" : "image/jpeg",
"size" : 28828,
"key" : "images-5BEe4maLCMFtHAZAj-wantedposter.jpg",
"updatedAt" : ISODate("2016-05-19T21:30:54Z"),
"createdAt" : ISODate("2016-05-19T21:30:54Z")
}
}
}
So I can do /uploadedimages/:key
QUESTION
Is there a way to get the key value from collectionFS?

AngularJS RESTful API Best Practices to maintain $scope

It is not clear to me the best practice for maintaining $scope of objects when making calls to a RESTful API. The problem I'm having is working with a Schema that has nested sub arrays, see below.
Is it best practice when making RESTful API call to expect a full JSON document in the response to update the $scope, or should I be able to maintain $scope on the client with Angular with nothing more than a http response code (ie 200)? It makes sense when making updates to the user object, but when I need to update profiles or favorites sections of the document, I'm just passing that portion of the document to the API and getting an http reponse code back, and my $scope doesn't reflect with the change, especially when pushing or pulling over PATCH route.
{
"_id" : ObjectId("558d53eebdd9804820090fa1"),
"name" : "Frank",
"email" : "Frank#FrankTheTank.com",
"profiles" : [
{
"avatar" : "div-male",
"age" : "35",
"gender" : "Male",
"profilename" : "Oly Lifter",
"_id" : ObjectId("558d5404bdd9804820090fa2"),
"favorites" : [
{
"name" : "Power Clean"
},
{
"name" : "Hang Clean"
},
{
"name" : "Clean and Jerk"
}
],
"createdAt" : ISODate("2015-06-26T13:30:44.661Z")
}
],
"createdAt" : ISODate("2015-06-26T13:30:22.884Z"),
"role" : "user"
}

Resources