Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ api

### api.triggerBroadcast(campaign_id, data, recipients)

Trigger an email broadcast using the email campaign's id. You can also optionally pass along custom data that will be merged with the liquid template, and additional conditions to filter recipients.
Trigger an email broadcast using the broadcast ID. You can also optionally pass along custom data that will be merged with the liquid template, and additional conditions to filter recipients.

```javascript
api.triggerBroadcast(1, { name: "foo" }, { segment: { id: 7 } });
Expand Down
4 changes: 2 additions & 2 deletions lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class APIClient {
return this.request.get(`${this.apiRoot}/customers?email=${cleanEmail(email)}`);
}

triggerBroadcast(id: string | number, data: RequestData, recipients: Recipients) {
triggerBroadcast(broadcastId: string | number, data: RequestData, recipients: Recipients) {
let payload = {};
let customRecipientField = (
Object.keys(BROADCASTS_ALLOWED_RECIPIENT_FIELDS) as BroadcastsAllowedRecipientFieldsKeys[]
Expand All @@ -138,7 +138,7 @@ export class APIClient {
};
}

return this.request.post(`${this.apiRoot}/api/campaigns/${id}/triggers`, payload);
return this.request.post(`${this.apiRoot}/campaigns/${broadcastId}/triggers`, payload);
Comment thread
washam-cio marked this conversation as resolved.
}

listExports() {
Expand Down
12 changes: 6 additions & 6 deletions test/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ test('#triggerBroadcast works', (t) => {
sinon.stub(t.context.client.request, 'post');
t.context.client.triggerBroadcast(1, { type: 'data' }, { type: 'recipients' });
t.truthy(
(t.context.client.request.post as SinonStub).calledWith(`${RegionUS.apiUrl}/api/campaigns/1/triggers`, {
(t.context.client.request.post as SinonStub).calledWith(`${RegionUS.apiUrl}/campaigns/1/triggers`, {
data: { type: 'data' },
recipients: { type: 'recipients' },
}),
Expand All @@ -274,7 +274,7 @@ test('#triggerBroadcast works with emails', (t) => {
},
);
t.truthy(
(t.context.client.request.post as SinonStub).calledWith(`${RegionUS.apiUrl}/api/campaigns/1/triggers`, {
(t.context.client.request.post as SinonStub).calledWith(`${RegionUS.apiUrl}/campaigns/1/triggers`, {
data: { type: 'data' },
emails: ['test@email.com'],
email_ignore_missing: true,
Expand All @@ -287,7 +287,7 @@ test('#triggerBroadcast works with ids', (t) => {
sinon.stub(t.context.client.request, 'post');
t.context.client.triggerBroadcast(1, { type: 'data' }, { ids: [1], id_ignore_missing: true });
t.truthy(
(t.context.client.request.post as SinonStub).calledWith(`${RegionUS.apiUrl}/api/campaigns/1/triggers`, {
(t.context.client.request.post as SinonStub).calledWith(`${RegionUS.apiUrl}/campaigns/1/triggers`, {
data: { type: 'data' },
ids: [1],
id_ignore_missing: true,
Expand All @@ -300,7 +300,7 @@ test('#triggerBroadcast works with per_user_data', (t) => {
const per_user_data = [{ id: 1, data: { very: 'important' } }];
t.context.client.triggerBroadcast(1, { type: 'data' }, { per_user_data, id_ignore_missing: true });
t.truthy(
(t.context.client.request.post as SinonStub).calledWith(`${RegionUS.apiUrl}/api/campaigns/1/triggers`, {
(t.context.client.request.post as SinonStub).calledWith(`${RegionUS.apiUrl}/campaigns/1/triggers`, {
data: { type: 'data' },
per_user_data,
id_ignore_missing: true,
Expand All @@ -313,7 +313,7 @@ test('#triggerBroadcast works with data_file_url', (t) => {
const data_file_url = 'https://my.s3.bucket.com';
t.context.client.triggerBroadcast(1, { type: 'data' }, { data_file_url, id_ignore_missing: true });
t.truthy(
(t.context.client.request.post as SinonStub).calledWith(`${RegionUS.apiUrl}/api/campaigns/1/triggers`, {
(t.context.client.request.post as SinonStub).calledWith(`${RegionUS.apiUrl}/campaigns/1/triggers`, {
data: { type: 'data' },
data_file_url,
id_ignore_missing: true,
Expand All @@ -334,7 +334,7 @@ test('#triggerBroadcast discards extraneous fields', (t) => {
},
);
t.truthy(
(t.context.client.request.post as SinonStub).calledWith(`${RegionUS.apiUrl}/api/campaigns/1/triggers`, {
(t.context.client.request.post as SinonStub).calledWith(`${RegionUS.apiUrl}/campaigns/1/triggers`, {
data: { type: 'data' },
ids: [1],
id_ignore_missing: true,
Expand Down
5 changes: 1 addition & 4 deletions test/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,7 @@ test.serial('#handler makes a request and rejects with a bad JSON response', asy

t.fail();
} catch (err: any) {
t.is(
err.message,
'Unable to parse JSON. Error: SyntaxError: Unexpected token < in JSON at position 0 \nBody:\n <html></html>',
);
t.regex(err.message, /Unexpected token <|Unable to parse JSON/);
}
});

Expand Down
Loading