-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
The Beehiiv API by default only allows retrieving 10 custom fields at a time: https://developers.beehiiv.com/api-reference/custom-fields/index
However in the SDK, there doesn't seem to be a way to input a limit or page parameter, which makes it impossible to retrieve all the custom fields (can only ever retrieve the first 10):
typescript-sdk/src/api/resources/customFields/client/Client.ts
Lines 274 to 386 in c2972a9
/** | |
* List all custom fields on a publication | |
* | |
* @param {Beehiiv.PublicationId} publicationId - The prefixed ID of the publication object | |
* @param {CustomFields.RequestOptions} requestOptions - Request-specific configuration. | |
* | |
* @throws {@link Beehiiv.BadRequestError} | |
* @throws {@link Beehiiv.NotFoundError} | |
* @throws {@link Beehiiv.TooManyRequestsError} | |
* @throws {@link Beehiiv.InternalServerError} | |
* | |
* @example | |
* await client.customFields.index("publicationId") | |
*/ | |
public async index( | |
publicationId: Beehiiv.PublicationId, | |
requestOptions?: CustomFields.RequestOptions | |
): Promise<Beehiiv.CustomFieldIndexResponse> { | |
const _response = await (this._options.fetcher ?? core.fetcher)({ | |
url: urlJoin( | |
(await core.Supplier.get(this._options.environment)) ?? environments.BeehiivEnvironment.Default, | |
`publications/${encodeURIComponent(serializers.PublicationId.jsonOrThrow(publicationId))}/custom_fields` | |
), | |
method: "GET", | |
headers: { | |
Authorization: await this._getAuthorizationHeader(), | |
"X-Fern-Language": "JavaScript", | |
"X-Fern-SDK-Name": "@beehiiv/sdk", | |
"X-Fern-SDK-Version": "0.1.6", | |
"User-Agent": "@beehiiv/sdk/0.1.6", | |
"X-Fern-Runtime": core.RUNTIME.type, | |
"X-Fern-Runtime-Version": core.RUNTIME.version, | |
}, | |
contentType: "application/json", | |
requestType: "json", | |
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, | |
maxRetries: requestOptions?.maxRetries, | |
abortSignal: requestOptions?.abortSignal, | |
}); | |
if (_response.ok) { | |
return serializers.CustomFieldIndexResponse.parseOrThrow(_response.body, { | |
unrecognizedObjectKeys: "passthrough", | |
allowUnrecognizedUnionMembers: true, | |
allowUnrecognizedEnumValues: true, | |
skipValidation: true, | |
breadcrumbsPrefix: ["response"], | |
}); | |
} | |
if (_response.error.reason === "status-code") { | |
switch (_response.error.statusCode) { | |
case 400: | |
throw new Beehiiv.BadRequestError( | |
serializers.Error_.parseOrThrow(_response.error.body, { | |
unrecognizedObjectKeys: "passthrough", | |
allowUnrecognizedUnionMembers: true, | |
allowUnrecognizedEnumValues: true, | |
skipValidation: true, | |
breadcrumbsPrefix: ["response"], | |
}) | |
); | |
case 404: | |
throw new Beehiiv.NotFoundError( | |
serializers.Error_.parseOrThrow(_response.error.body, { | |
unrecognizedObjectKeys: "passthrough", | |
allowUnrecognizedUnionMembers: true, | |
allowUnrecognizedEnumValues: true, | |
skipValidation: true, | |
breadcrumbsPrefix: ["response"], | |
}) | |
); | |
case 429: | |
throw new Beehiiv.TooManyRequestsError( | |
serializers.Error_.parseOrThrow(_response.error.body, { | |
unrecognizedObjectKeys: "passthrough", | |
allowUnrecognizedUnionMembers: true, | |
allowUnrecognizedEnumValues: true, | |
skipValidation: true, | |
breadcrumbsPrefix: ["response"], | |
}) | |
); | |
case 500: | |
throw new Beehiiv.InternalServerError( | |
serializers.Error_.parseOrThrow(_response.error.body, { | |
unrecognizedObjectKeys: "passthrough", | |
allowUnrecognizedUnionMembers: true, | |
allowUnrecognizedEnumValues: true, | |
skipValidation: true, | |
breadcrumbsPrefix: ["response"], | |
}) | |
); | |
default: | |
throw new errors.BeehiivError({ | |
statusCode: _response.error.statusCode, | |
body: _response.error.body, | |
}); | |
} | |
} | |
switch (_response.error.reason) { | |
case "non-json": | |
throw new errors.BeehiivError({ | |
statusCode: _response.error.statusCode, | |
body: _response.error.rawBody, | |
}); | |
case "timeout": | |
throw new errors.BeehiivTimeoutError(); | |
case "unknown": | |
throw new errors.BeehiivError({ | |
message: _response.error.errorMessage, | |
}); | |
} | |
} |
Metadata
Metadata
Assignees
Labels
No labels