### Initializing and Using OAuth Client for Amazon Advertising API in TypeScript Source: https://github.com/scaleleap/amazon-advertising-api-sdk/blob/master/README.md This example demonstrates how to initialize the `OAuthClient` with credentials and use its methods to manage OAuth flow. It shows how to get the redirect URI, obtain a new token, and refresh an existing token, which are crucial for authentication with the Amazon Advertising API. ```ts import { OAuthClient } from '@scaleleap/amazon-advertising-api-sdk' const client = new OAuthClient({ clientId: '...', clientSecret: '...', redirectUri: '...', }) // get redirect URL to send the user to start OAuth flow const uri = client.getUri() // get token const token = client.getToken() // refresh existing token const token = client.createToken('... access token ...', '... refresh token ...') const res = await token.refresh() ``` -------------------------------- ### Installing Amazon Advertising API SDK with npm Source: https://github.com/scaleleap/amazon-advertising-api-sdk/blob/master/README.md This snippet provides the command to install the `@scaleleap/amazon-advertising-api-sdk` package using npm. It's a prerequisite for using the SDK in a Node.js or TypeScript project. ```sh npm i -s @scaleleap/amazon-advertising-api-sdk ``` -------------------------------- ### Listing Profiles using OperationProvider in TypeScript Source: https://github.com/scaleleap/amazon-advertising-api-sdk/blob/master/docs/README.md This example shows how to create an OperationProvider and then use it to instantiate a ProfileOperation. It proceeds to call the listProfiles method on the ProfileOperation instance, demonstrating a common pattern for retrieving data from the Amazon Advertising API. ```TypeScript import { HttpClient, OperationProvider, ProfileOperation } from '@scaleleap/amazon-advertising-api-sdk' const operationProvider = new OperationProvider(httpClient) const profileOperation = operationProvider.create(ProfileOperation) // Using ProfileOperation to list profiles const res = await profileOperation.listProfiles() ``` -------------------------------- ### Initializing AmazonAdvertising Class with HttpClient in TypeScript Source: https://github.com/scaleleap/amazon-advertising-api-sdk/blob/master/docs/README.md This example illustrates how to create an instance of the AmazonAdvertising class, which internally utilizes an HttpClient. It requires specifying the Amazon marketplace and authentication details, and includes a prerequisite check to ensure the marketplace supports advertising. ```TypeScript import { amazonMarketplaces, assertMarketplaceHasAdvertising } from '@scaleleap/amazon-marketplaces' import { AmazonAdvertising} from '@scaleleap/amazon-advertising-api-sdk' assertMarketplaceHasAdvertising(amazonMarketplaces.US) const amazonAdvertising = new AmazonAdvertising(amazonMarketplaces.US, auth) ``` -------------------------------- ### Creating Operations Directly from Class in TypeScript Source: https://github.com/scaleleap/amazon-advertising-api-sdk/blob/master/docs/README.md This example presents an alternative method for creating an operation object by directly calling a static 'create' method on the operation class itself. It requires passing the HttpClient instance to this static method, offering a more direct way to instantiate operations. ```TypeScript import { HttpClient } from '@scaleleap/amazon-advertising-api-sdk' const httpClient = new HttpClient('https://advertising-api.amazon.com', auth) const profileOperation = ProfileOperation.create(httpClient) // Using ProfileOperation to list profiles const res = await profileOperation.listProfiles() ``` -------------------------------- ### Fetching OAuth Token (TypeScript) Source: https://github.com/scaleleap/amazon-advertising-api-sdk/blob/master/docs/README.md This example illustrates how to retrieve an OAuth token using the getToken method of the OAuthClient. The returned token object will be of type Token from the client-oauth2 package, containing access and refresh tokens. ```TypeScript const token = client.getToken() ``` -------------------------------- ### Creating HttpClient with OAuth Authentication (TypeScript) Source: https://github.com/scaleleap/amazon-advertising-api-sdk/blob/master/docs/README.md This example shows how to instantiate an HttpClient for making API requests, using an authentication object containing an accessToken, clientId, and a scope (typically the Profile ID). The HttpClient is configured with the base URL for the Amazon Advertising API. ```TypeScript const auth = { accessToken: "ACCESS_TOKEN", clientId: "YOUR_CLIENT_ID", scope: 10000000000 // Use your Profile ID as the value for the management scope } const httpClient = new HttpClient('https://advertising-api.amazon.com', auth) ``` -------------------------------- ### Fetching PollyJS Recordings via Git Shell Source: https://github.com/scaleleap/amazon-advertising-api-sdk/blob/master/CONTRIBUTING.md This command allows developers to easily fetch PollyJS recordings generated by the CI process. It first fetches all remote branches and then cherry-picks the latest commit from the 'polly-recordings' branch, which contains the recorded API interactions. ```sh git fetch && git cherry-pick -x "$(git rev-parse origin/polly-recordings)" ``` -------------------------------- ### Creating OperationProvider and Operations with HttpClient in TypeScript Source: https://github.com/scaleleap/amazon-advertising-api-sdk/blob/master/docs/README.md This snippet demonstrates the process of instantiating an OperationProvider using an HttpClient. It then shows how to use this provider to create specific operation objects, such as ProfileOperation, which are used to interact with different parts of the Amazon Advertising API. ```TypeScript import { OperationProvider, HttpClient, ProfileOperation } from '@scaleleap/amazon-advertising-api-sdk' const httpClient = new HttpClient('https://advertising-api.amazon.com', auth) // A provider instance, that knows how to instantiate operation classes const operationProvider = new OperationProvider(httpClient) // Instantiate an "operation" object const profileOperation = operationProvider.create(ProfileOperation) ``` -------------------------------- ### Performing API Operations with Amazon Advertising API SDK in TypeScript Source: https://github.com/scaleleap/amazon-advertising-api-sdk/blob/master/README.md This snippet illustrates the process of making API calls using the SDK's `HttpClient` and `OperationProvider`. It shows how to instantiate an operation class, such as `ProfileOperation`, and then use it to interact with specific API endpoints, like listing profiles, providing a structured way to access different parts of the Amazon Advertising API. ```ts import { HttpClient, OperationProvider, ProfileOperation } from '@scaleleap/amazon-advertising-api-sdk' // HTTP Client, tailored for the Amazon Advertising API // See other endpoints: https://advertising.amazon.com/API/docs/en-us/get-started/how-to-use-api const httpClient = new HttpClient('https://advertising-api.amazon.com', auth) // A provider instance, that knows how to instantiate operation classes const operationProvider = new OperationProvider(httpClient) // Instantiate an "operation" object const profileOperation = operationProvider.create(ProfileOperation) // Using the operation object to make API calls const res = await profileOperation.listProfiles() ``` -------------------------------- ### Creating HttpClient with OAuthClient in TypeScript Source: https://github.com/scaleleap/amazon-advertising-api-sdk/blob/master/docs/README.md This snippet demonstrates how to initialize the HttpClient using authentication details obtained from an OAuthClient. It specifies the accessToken, clientId, and scope (Profile ID) required for API access, setting up the foundation for subsequent requests. ```TypeScript import { HttpClient } from '@scaleleap/amazon-advertising-api-sdk' // `client` is of type `OAuthClient` const auth = { accessToken: (client.getToken()).accessToken, clientId: "YOUR_CLIENT_ID", scope: 10000000000 // Use your Profile ID as the value for the management scope } const httpClient = new HttpClient('https://advertising-api.amazon.com', auth) ``` -------------------------------- ### Initializing OAuthClient for Amazon Advertising API (TypeScript) Source: https://github.com/scaleleap/amazon-advertising-api-sdk/blob/master/docs/README.md This snippet demonstrates how to create an instance of OAuthClient using the Amazon Advertising API SDK. It requires clientId, clientSecret, and redirectUri for OAuth2 authentication, along with a specified Amazon marketplace to ensure advertising capabilities. ```TypeScript import { OAuthClient } from '@scaleleap/amazon-advertising-api-sdk' import { amazonMarketplaces, assertMarketplaceHasAdvertising } from '@scaleleap/amazon-marketplaces' assertMarketplaceHasAdvertising(amazonMarketplaces.US) const client = new OAuthClient({ clientId: '...', clientSecret: '...', redirectUri: '...' }, amazonMarketplaces.US) ``` -------------------------------- ### Listing Profiles using AmazonAdvertising Class in TypeScript Source: https://github.com/scaleleap/amazon-advertising-api-sdk/blob/master/docs/README.md This snippet illustrates how to leverage the AmazonAdvertising class to access and invoke API operations. It specifically demonstrates retrieving user profiles by accessing the 'profile' property of the AmazonAdvertising instance and calling its listProfiles method. ```TypeScript import { amazonMarketplaces } from '@scaleleap/amazon-marketplaces' import { AmazonAdvertising } from '@scaleleap/amazon-advertising-api-sdk' assertMarketplaceHasAdvertising(amazonMarketplaces.US) const amazonAdvertising = new AmazonAdvertising(amazonMarketplaces.US, auth) const profileOperation = amazonAdvertising.profile // Using ProfileOperation to list profiles const res = await profileOperation.listProfiles() ``` -------------------------------- ### Re-creating OAuth Access Token Instance (TypeScript) Source: https://github.com/scaleleap/amazon-advertising-api-sdk/blob/master/docs/README.md This snippet shows how to re-create an access token instance using existing accessToken and refreshToken values via the createToken method. This is useful for making subsequent requests on behalf of a user without re-initiating the full OAuth flow. ```TypeScript // const oldToken: Token const token = client.createToken(oldToken.accessToken, oldToken.refreshToken) ``` -------------------------------- ### Retrieving OAuth Authorization URI (TypeScript) Source: https://github.com/scaleleap/amazon-advertising-api-sdk/blob/master/docs/README.md This snippet demonstrates how to obtain the authorization URI from the OAuthClient instance. This URI is used to initiate the OAuth 2.0 authorization flow, redirecting the user to Amazon's login page to grant permissions. ```TypeScript const uri = client.getUri() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.