Trying to get HTML of template
tiger5226 opened this issue · 5 comments
Unexpected server response code: 400: Unknown resource: "detailcontent" ()
exit status 1
func FetchTempate() {
publicKey := os.Getenv("MJ_APIKEY_PUBLIC")
secretKey := os.Getenv("MJ_APIKEY_PRIVATE")
mj := mailjet.NewMailjetClient(publicKey, secretKey)
var templ []resources.TemplateDetailcontent
info := &mailjet.Request{
Resource: "detailcontent",
ID: 561775,
}
err := mj.Get(info, &templ)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
logrus.Warning("HTML ", templ[0].HtmlPart)
logrus.Warning("Text ", templ[0].TextPart)
fmt.Printf("Sender struct: %+v\n", templ)
}
I can't seem to get the resource based on https://dev.mailjet.com/email-api/v3/template-detailcontent/
The example only works with single depth resources. like template
. I tried many different forms too. Please add an example of how to use template/:id/detailcontent
vs just template
which works fine.
Another added note is that I was frustrated enough to post an issue. Most users will not create issues. You should always try to reduce "assumed knowledge" as much as possible. If people don't have a recourse they most likely will pass over your solution than wait days potentially for a response.
I altered it to use the Action
, and modified the package to output the url it creates:
https://api.mailjet.com/v3/REST/template/561775/detailcontent
Which is correct based on my working postman example.
func FetchTempate() {
publicKey := os.Getenv("MJ_APIKEY_PUBLIC")
secretKey := os.Getenv("MJ_APIKEY_PRIVATE")
mj := mailjet.NewMailjetClient(publicKey, secretKey)
var templ []resources.TemplateDetailcontent
info := &mailjet.Request{
Resource: "template",
ID: 561775,
Action: "detailcontent",
}
err := mj.Get(info, &templ)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
//logrus.Warning("HTML ", templ.HtmlPart)
//logrus.Warning("Text ", templ.TextPart)
fmt.Printf("Sender struct: %+v\n", templ)
}
Now I get the following error:
Error decoding API response: json: cannot unmarshal object into Go struct field TemplateDetailcontent.MJMLContent of type string
exit status 1
Ok, so the v3 api has MJMLContent as an object. From my postman test, I can see this. Not sure why the library still has it as a string. So I need to build this out I guess in order to use this API.
Hi @tiger5226 ,
I'll close the issue as it's solved by the PR you mentioned.