How to send form as json in 11ty - json

I'm trying to send data from 11ty to my directus headless CMS.
The problem here is Directus only accepts json data.
No problem to send the data with regular website, but as 11ty is a static site generator, I can't find the way to send the data as json instead of form, because I can only use javascript for receiving data.
Thanks!

On your form, why not use JavaScript to handle the form submission and then use fetch() to hit the CMS? Basically, this is something you handle in client-side JS, via your generated site.

As I recall, Directus provides a collection endpoint, i.e. /items/contacts where you can directly POST your form submission.

Related

E-mail templates with Json

Working on a project for my employer. They are searching for a solution to connect JSON to a email template.
For now, I look for a solution where the system who has the JSON, loads the JSON script on a server. Then, we connect that server with a marketing automation system, for example Marketo. We like to create an email template which loads the JSON.
The developer we found, says it is not possible and it will not work in gmail, outlook or any other client. For what I know, it is possible to create a email template with JSON right? Just to be sure, because when it is possible, our problem is not the system, but the developer.
Like to hear your thoughts on this subject. Suggestions are welcome.
So, this can be done, but you're going to need to do some custom development.
Marketo's API includes a request campaign endpoint for triggering Smart Campaigns, including those which send emails. As part of the request campaign payload, you can send {{my.token}} values for the campaign.
If you can set up some middleware between your JSON output that renders the HTML for your email, you can push that rendered HTML as a token in the campaign request, allowing for on-demand email creation based on your JSON content.
There are two caveats with this approach:
You will have to dynamically send the email using Request Campaign. That means if you need to send unique content to multiple folks, you'll be using one API call per email.
Due to the nature of Request Campaign triggers, you will not be able to batch and send using Marketo's controls; however, this should be straightforward to set up on the API side.
You can build an email using dynamic data, e.g. from an API that sends JSON.
However, you cannot send an email that calls dynamic data. The final email that gets sent must be static. That may be what your developer is getting at. Email software will strip out scripts.

Sending canvas object with restfull api in django

I am using django as my backend and I am using restful api to communicate with react js frontend. I have created a pdf invoice with canvas and I was able to send it via mail system of django. But I also want to show the pdf on web page. So I need to send it to front end via api url. I tried to send it as response but I got the error:
Object of type Canvas is not JSON serializable
The code that I wrote to send pdf:
return Response(c, status=status.HTTP_200_OK)
c stands for the canvas object which is a pdf
Is there a solution of this? Or how do I send the pdf to the front end.
Thank you
I think you can send the static url(eg. 127:.0.0.1:8000/static/yourfile.pdf) for the pdf, which will be rendered by the browser. And you can add a button in your react frontend which will redirect to the pdf url.

How do I make an API query and display the Json result?

I'm using an API to receive information from a server. I'm authorising using a token. I can query using curl or various api testers online. But now I'm trying to learn how to implement (and request) the results in practice.
I'd like to query, parse and display the json result on a web page (preferably a Wordpress site).
So I need to make a get request, authorise myself using my token, and receive the result and then display it in a nice way.
How do I do that?
This is a vague question, not really sure if you are making requests from just one side but you have 2 options, albeit one being better than the other.
You can create add multiple functions inside your themes function.php file to extend its capabilities but again these are limited to only the theme you are using.
I would recommend that you build a plugin, this will give you the flexibility to use both JS and PHP to do whatever you need to do. With this method you can create a shortcode to display the results from your API query.
You will need to learn to use the Wordpress function wp_remote_get() to perform external API calls.
Here is a tutorial with more information:
Create Plugin and Create External API Calls
Parse JSON from Remote API
Hope this helps

email service for send an email with nodejs in angular 4.x?

I want to send an email activation code for users who sign up on the website. If possible, I would like to use an Angular service so I can use it later in other projects.
... I think you CAN NOT send an email only with Angular4 .. .but you need also a Back End implementation .. like node.js or Asp.NET or what you prefer...
example :
http://tphangout.com/angular-2-sending-mails-from-your-app/
I suppose you need to send from client side(not using a server side like node.js, web api, wcf etc..).
You can not send directly but using external javascript libraries, apis you might able to send. Take a look here, there are pretty much discussions about sending email with javascript.
How to send an email from JavaScript

Consume JSON in body of POST Request from ASP.NET

I need to be able to consume some JSON data in a POST request from another web app. I have tried looking at the various methods on the Request class, but nothing seems to give me the JSON I need.
Using Request.Form will not work, since it is not coming from a form, but another web app. The content type is application/json, and from examining the whole HTTP request, I know the JSON is in there. What is the best way to get at this JSON data?
Note: I am working from within an action on a controller.
I think you can get your JSON from your model parameter inside the Action of the Controller. Check out this article that explains a bit of what I mean.
You can also read this one for reference
Since you are consuming data from another web app I would use a REST web service instead of a controller in an MVC application. You cans use the ASP.NET Web API which makes it easy to setup a REST web API and it is tightly integrated in with MVC 4, which is now in Beta. If the communication is cross domain (i.e. different servers and/or ports) you will need to use JSONP. You can go to this StackOverflow QA for directions on how to use JSONP with Web API.