Reputation: 401
I created code in golang that is supposed to support the endpoint API (through get queries). That's documentation of API's endpoint: https://developer.dotdigital.com/docs/get-all-campaigns
Code looks like this:
type Campaign struct {
Id int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Subject string `json:"subject,omitempty"`
FromName string `json:"fromName,omitempty"`
FromAddress struct {
Id int `json:"id,omitempty"`
Email string `json:"email,omitempty"`
}
HtmlContent string `json:"htmlContent,omitempty"`
PlainTextContent string `json:"plainTextContent,omitempty"`
ReplyAction string `json:"replyAction,omitempty"`
IsSplitTest bool `json:"isSplitTest,omitempty"`
Status string `json:"status,omitempty"`
}
func (dcfg DotmailerApiConfig) GetContacts2() ([]*dotmailermodels.Contact) {
var (
allContacts, respContacts []*dotmailermodels.Contact
selected = 1000
skip = 0
err error
)
for true {
url := dcfg.Url + fmt.Sprintf("v2/contacts?withFullData=%s&select=%s&skip=%s",
strconv.FormatBool(false),
strconv.Itoa(selected),
strconv.Itoa(skip))
resp := dcfg.GetRequesDotmailertBuilder(url)
err = json.Unmarshal(resp, &respContacts)
if err != nil {
Error.Println(err) // just error trace
}
allContacts = append(allContacts, respContacts...)
if len(respContacts) == 1000 {
skip += 1000
respContacts = nil
continue
}
break
}
return allContacts
}
When I'm running on my PC I get the correct response. When I use it in Lambda I get this error:
[ERROR] 2019/03/24 18:37:26 dotmailergetrequests.go:110: json: cannot unmarshal object into Go value of type []*dotmailermodels.Campaign
Have you got any idea why?
Upvotes: 0
Views: 1555
Reputation: 401
I found that error. Everything was correct - except password import in the other file.
Upvotes: 0
Reputation: 1547
try this:
type Address struct {
Id int `json:"id,omitempty"`
Email string `json:"email,omitempty"`
}
type Campaign struct {
Id int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Subject string `json:"subject,omitempty"`
FromName string `json:"fromName,omitempty"`
FromAddress *Address `json:"fromAddress,omitempty"`
HtmlContent string `json:"htmlContent,omitempty"`
PlainTextContent string `json:"plainTextContent,omitempty"`
ReplyAction string `json:"replyAction,omitempty"`
IsSplitTest bool `json:"isSplitTest,omitempty"`
Status string `json:"status,omitempty"`
}
Upvotes: 1