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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineAction({
name: "Create Subscriber",
description: "Create a new subscriber. [See docs](https://www.beehiiv.com/developers/docs)",
key: "beehiiv-create-subscriber",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
app,
Expand Down Expand Up @@ -49,7 +49,7 @@ export default defineAction({
utm_source: this.utmSource,
};
const response = await this.app.createSubscriber($, param);
$.export("$summary", `Successfully created a new subscriber with id: ${response.id}`);
$.export("$summary", `Successfully created a new subscriber with id: ${response.data.id}`);
return response;
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineAction({
name: "List All Publications",
description: "Get a list of all your publications. [See docs](https://www.beehiiv.com/developers/docs)",
key: "beehiiv-list-all-publications",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
app,
Expand Down
19 changes: 12 additions & 7 deletions components/beehiiv/app/beehiiv.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default defineApp({
reactivateExisting: {
type: "boolean",
label: "Reactivate Existing",
description: "Whether or not to reactivate the subscriber if they have already unsubscribed. **This option should be used only if the subscriber is knowingly resubscribing**. default: `false`.",
description: "Whether or not to reactivate the subscriber if they have already unsubscribed. **This option should be used only if the subscriber is knowingly resubscribing**. default: `false`.",
optional: true,
},
sendWelcomeEmail: {
Expand All @@ -38,27 +38,32 @@ export default defineApp({
},
},
methods: {
_getUrl(path) {
return `https://api.beehiiv.com/v1${path}`;
_getUrl(path, params = {}) {
let formattedPath = path;
for (const [key, value] of Object.entries(params)) {
formattedPath = formattedPath.replace(`{${key}}`, value);
}
return `https://api.beehiiv.com/v2${formattedPath}`;
},
_getHeaders(headers = {}) {
return {
"X-ApiKey": this.$auth.api_key,
"Authorization": `Bearer ${this.$auth.api_key}`,
"Content-Type": "application/json",
...headers,
};
},
_getRequestParams(opts: any) {
return {
...opts,
url: this._getUrl(opts.path),
url: this._getUrl(opts.path, opts.params),
headers: this._getHeaders(),
};
},
async createSubscriber($ = this, param) {
const response = await axios($, this._getRequestParams({
method: "POST",
path: "/subscribers",
path: "/publications/{publicationId}/subscriptions",
params: { publicationId: param.publication_id },
data: param,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok for publication_id to be included in the request body as well, since it is being used as a query param?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so!

}));
return response;
Expand All @@ -68,7 +73,7 @@ export default defineApp({
method: "GET",
path: "/publications",
}));
return response;
return { publications: response.data };
},
async getPublicationOpts() {
const { publications } = await this.listPublications(this);
Expand Down
2 changes: 1 addition & 1 deletion components/beehiiv/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/beehiiv",
"version": "0.0.4",
"version": "0.0.5",
"description": "Pipedream Beehiiv Components",
"main": "dist/app/beehiiv.app.mjs",
"keywords": [
Expand Down
18 changes: 18 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.