Mailchimp (mandrill) transactional emails: how to add custom data to email templates? - mailchimp

I want to be able to send an email template to a customer which contains some data that is specific to the individual customer (e.g an order number, or a temporary password)
I've designed an email template which I intend to send to customers, but I'm not sure how to add this dynamic data to the template.
I'm using the API to send emails to customers, and I've learnt that you can send templates to customers with a request like so:
POST: https://mandrillapp.com/api/1.0/messages/send-template
Request Body:
{"key":"myApiKey","template_name":"test","template_content":[],"message":{"html":"","text":"","subject":"Template sending test","from_email":"someEmail","from_name":"Company Name","to":[{"email": "someOtherEmail", "type": "to"}]}}
Is it possible to add custom data such as { "orderNumber": "12345" } to the json, and if so how would the template know to render that in in the template email? I assume there must be a field you create which corresponds to the data in the post request.
I had a look at the metadata tags in the documentation, which allow you to add "custom, individualized metadata to messages" but it doesn't sound like you can add this data to an email template?

Ok.... If I had actually just continued reading the documentation it tells you how to do this!
https://mailchimp.com/developer/transactional/docs/templates-dynamic-content/#editable-content-areas
So you can add this html in your email template:
<div mc:edit="main">
Content to be replaced.
</div>
And then in my json, I can add replacement content for this area of the email in "template_content" (obviously!).
{
"key":"myApiKey",
"template_name":"test",
"template_content":[
{
"name":"main",
"content":"Hello World - content replaced"
}
],
"message":{
"html":"",
"text":"",
"subject":"Template sending test",
"from_email":"someEmail",
"from_name":"Company Name",
"to":[
{
"email":"someOtherEmail",
"type":"to"
}
]
}
}

Related

Post data to custom AL field in Business Central

I am trying to create an API call to add data into a custom field that was created on the Sales Order page using AL Extensions. The issue is when I try to do the api call through postman, I am getting "The Property "propertyName" does not exist on type 'Microsoft.NAV.salesOrder'". First of all, I don't even know if the API allows for this, so is it even possible? And secondly, if it is possible, is there a certain way to set up the API call or the Field through the AL Extension?
tableextension 50100 "AddProjectIdToSalesOrder" extends "Sales Header"
{
fields
{
field(50100; "CrmProjectId"; Guid)
{
Caption = 'Crm Project Id';
DataClassification = OrganizationIdentifiableInformation;
}
}
}
pageextension 50100 "AddProjectIdToSalesOrder" extends "Sales Order"
{
layout
{
addlast(General)
{
field("CRM Project Id"; Rec.CrmProjectId)
{
ApplicationArea = all;
ToolTip = 'The Guid of the related Project Record in the CRM environment';
}
}
}
}
This is how I am setting up the field with the AL extension, and for the post call, I am just creating a new Sales Order with a post and the body looks like:
{
"customerNumber" : "10000",
"CrmProjectId" : "random-guid"
}
And the error is "Bad Request": "The property 'CrmProjectId' does not exist on type 'Microsoft.NAV.salesOrder'. Make sure to only use property names that are defined by the type." Any help would be appreciated.
The Sales Order API is a separate page. It is not equivalent to the Sales Order page so you have to modify the API to accomplish what you want.
However the standard API's provided by Microsoft can't be extended.
You are left with two options:
Make a copy of the standard Sales Order API (this involves making a copy of all the linked APIs as well e.g. the Sales Line API).
Create a new API page with the single purpose of updating your new field. Then you would use the standard Sales Order API to create the Sales Order and then update CrmProjectId with a second call to your custom API page.

Send array to api via postman?

Beginner in API
I have table post_tag which is posts table has relation ( many to many ) with tags table.
my controller code ( every thing is good ):
$post = Post::create($data);
$post->tag()->attach($request->tags);
return $this->apiRespone($post , 'Added Post Successfuly', null ,200);
My question is here: now I send array of tags like that! Is that the best way or the correct way to send array ( means when I give this api url to mobile developer, he will know what to do with this api url ?
My way is correct or not ?
Although your solution works, a better approach since you are building an endpoint, it would be better to switch your input to accept JSON format rather than using form-data. Make your API endpoint to accept the following payload:
{
"title": "First Post",
"desc": "Desc of Post",
"image": "image3.jpg",
"category_id": 1,
"tags": [
"one",
"two",
"three"
]
}
In Laravel, you get just grab the tags (or any other properties) with the following:
$tags = $request->input('tags');
For the image, you can allow it to be received in base64 encoded image. The image will look like a bunch of string which should be converted by the client (ios or android) e.g:
{
image:"/9j/4AAQSkZJRgABAQAAAQABAAD/7QB8UGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAF8cAigAWkZCTUQyMzAwMDk2OTAxMDAwMDgxNTIwMDAwNWY2MDAwMDA3NDZmMDAwMDE2YmEwMDAwNDAxYjAxMDBmMTM0MDEwMGY4YzIwMTAwZDkxNDAyMDA1ZDRhMDIwMAD/2wBDAAcHBwcHBwwHBwwRDAwMERcRERERFx4XFxcXFx4kHh4eHh4eJCQkJCQkJCQrKysrKysyMjIyMjg4O"
}
Then in PHP, if you want to save the image on disk, just use base64_decode. See example here.

Microsoft 365 API : Issue at attaching Contact to Campaign Response

I am trying to attach a contact to campaign response.
I am using rest API for that.
https://learn.microsoft.com/en-us/dynamics365/customer-engagement/web-api/campaignresponse?view=dynamics-ce-odata-9
Post Data :
{
"firstname": "TestFirst",
"lastname": "TestLast",
"emailaddress": "test#test.com",
"telephone": "1234567890",
"prioritycode": 0,
"responsecode": 1,
"subject": "Test Subject",
"statuscode": 1,
"regardingobjectid_campaign#odata.bind": "/campaigns(xxxx90c-11ef-e811-a966-000d3ad24a0d)",
"regardingobjectid_contact#odata.bind": "/contacts(xxxxfa2e-c3b5-e811-a962-000d3ad24a0d)"
}
Here is my JSON.
I am getting Error : “Campaign as RegardingObject must be supplied”. Without contact, it works fine.
I had the same problem and the documentation is not very clear about it, I had to check all the relationships of the CampaignResponse in order to understand how to solve this.
If you want to create a CampaignResponse linked to both a Campaign and a Contact you need to do the following:
Create a CampaignResponse with the "regardingobjectid_campaign#odata.bind" in the params sent.
POST "https://some_subdomain.crm6.dynamics.com/api/data/v9.0/campaignresponses"
{
"regardingobjectid_campaign#odata.bind": "/campaigns(CAMPAIGN_ID_HERE)",
"description": "some desc",
"subject": "some subject "
}
Then find the CampaignResponse you just created to get its activityid (every CampaignResponse is an Activity)
Finally, you need to create a new ActivityParty, that will link the Contact to the CampaignResponse.
POST "https://some_subdomain.crm6.dynamics.com/api/data/v9.0/campaignresponses(CAMPAIGN_ID_HERE)/activitypointer_activity_parties"
{
"partyid_contact#odata.bind": "/contacts(CONTACT_ID_HERE)",
"participationtypemask": 11 //this is the code for customers
}
The "Regarding" lookup field can only be set to a single "regarding" record. Even though it appears that there are different Regarding fields, one for each entity type, those are "helper" fields that let you easily set the main Regarding field by setting one of those regardingobjectid_xxx fields.
You must choose to use either a campaign or a contact as your Regarding field. You can of course create other lookups, so you could use the Regarding field for your campaign and then add an additional Contact lookup field, for example.

(Ember.js) How to save Sideloaded data from ajax call?

Good day!
Just want to ask on how to create a JSONAPISerializer for an ajax call?
From what I understand on the docs. I must first create a model before I can make a JSONAPISerializer. But I need to call a custom endpoint that is not listed as my model.
My goal is to pushPayload all the sideloaded data coming from my endpoint. but the problem is :
{
"data":[
{
"type":"promotions-verify", <----- it's not an actual model
"attributes":{
"cart-items-discount-in-cents":21900
},
"relationships":{...}, <---- sideloaded data that I want to push on ember-data
}],
"included": [] <---- sideloaded data that I want to push on ember-data
}
Is there a reason you can't make a model for promotions-verify? That would be the cleanest way to implement loading in the side-loaded data, since Ember would handle much of the serialization/pushing to the store for you.
If that isn't possible and you make an ajax request, you may need to map the relationships and included payloads to match up with one another (Lodash _.map() could work well for this). Then you can manually push that data (pushPayload) to the Ember store, while ensuring that the items you're pushing also have models and serializers.
Also, I'm not sure if this was accidental, but your example payload doesn't conform to JSON API standards – the relationships object should be nested within data. This will affect how Ember serializes the data, as it's expecting:
{
"data": [{
"id": 1,
"type": "promotions-verify",
"attributes": {},
"relationships": {}
}],
"included": []
}

How to share location with public tag with Glympse REST API

I am trying to share a location to a public tag in Glympse with their REST API. My application is creating a ticket with
/v2/users/self/create_ticket
After that I am trying to add that ticket to the public tag/group (which is already available).
/v2/tickets/${ticketid}/append_data
{
[
"t": ${timestamp},
"pid": 0,
"n": "card_id",
"v": card_id // I am putting the group ID here
]
}
After that I have no clue how to proceed. I find the Glympse API description very confusing, so I tried several API functions but none of them worked, like updating the card
/v2/cards/${groupdid}/ticket
error: { result: 'failure', response: {}, meta: { error: 'invalid_access',
error_detail: 'Error processing request',
time: 1506944558077 } }
or simply just adding location data (no error but nothing visible in the tag)
/v2/tickets/${ticketid}/append_location.
Can you help me with the flow how to share the data to a public tag? I cannot find anything like that for the REST API. I could find this link: https://developer.glympse.com/docs/core/client-sdk/guides/common/groups but it does not help me with JavaScript and REST.
Thank you
Cards are only for private groups. To share to a public group (public tag) after you create the ticket, you create an invite of type "group" where the address is the name of the tag.
https://developer.glympse.com/docs/core/api/reference/tickets/id/create_invite/post
The group type appears to be missing from that reference page, but that is the type to use.
For example, to share to a tag named "testtag123":
tickets/[ticket_id]/create_invite?locale=en_US&region=en_US&type=group&send=server&address=testtag123&name=testtag123

Resources