Se connecter à l'API partenaire de vente à l'aide d'un SDK C# généré

Connectez-vous à l'API SP à l'aide d'un SDK C# généré.

This tutorial describes how to use a generated C# Software Developer Kit (SDK) to make API calls. The SDK exposes classes for configuring your Login with Amazon (LWA) credentials and uses them to generate LWA tokens and sign requests for you. For more information, refer to Generate a C# SDK with LWA token generation and authentication.

Before your application can connect to the Selling Partner API, you must register it and a selling partner must authorize it. Refer to Registering your application and Authorizing Selling Partner API applications.

You must also install the following dependencies via NuGet in Visual Studio:

  • JsonSubTypes 1.2.0 ou tout
  • Newtonsoft.json 12.0.3 ou tout
  • RestSharp 106.12.0
  • RateLimiter 2.2.0 ou plus récent (cela installera également ComposableAsync.Core)

Étape 3. Configurer vos informations d'identification LWA

Créez une instance de LWAAuthorizationCredentials à l'aide des paramètres suivants :

NomDescriptionObligatoire
ClientIdYour LWA client identifier. For more information, refer to Viewing your application information and credentials.Oui
ClientSecretYour LWA client secret. For more information, refer to Viewing your application information and credentials.Oui
RefreshTokenThe LWA refresh token. Get this value when the selling partner authorizes your application. For more information, refer to Authorizing Selling Partner API applications. No. Include RefreshToken if the operation that you call in the following step requires selling partner authorization. All operations that are not grantless operations require selling partner authorization. If you include RefreshToken, do not include Scopes.
Scopes

The scope of the LWA authorization grant. Takes the value ScopeNotificationsAPI for the Notifications API.

No. Include Scopes if the operation that you call in the following step is a grantless operation. If you include Scopes, do not include the RefreshToken.
EndpointURI du serveur d'authentification LWA.Oui

Exemple d'appel d'opération nécessitant l'autorisation d'un partenaire commercial :

using Amazon.SellingPartnerAPIAA; LWAAuthorizationCredentials lwaAuthorizationCredentials = new LWAAuthorizationCredentials { ClientId = "myClientId", ClientSecret = "myClientSecret", RefreshToken = "Aztr|...", Endpoint = new Uri(""https://api.amazon.com/auth/o2/token"") };

Exemple d'appel vers une opération sans autorisation

using Amazon.SellingPartnerAPIAA; LWAAuthorizationCredentials lwaAuthorizationCredentials = new LWAAuthorizationCredentials { ClientId = "myClientId", ClientSecret = "myClientSecret", Scopes = new List<string>() { ScopeConstants.ScopeNotificationsAPI, ScopeConstants.ScopeMigrationAPI } Endpoint = new Uri(""https://api.amazon.com/auth/o2/token"") };

Étape 3. Créer une instance de l'API Vendeurs et appeler une opération

After you configure your LWAAuthorizationCredentials, you can create an instance of SellersApi and call an operation.

Exemple :

SellersApi sellersApi = new SellersApi.Builder() .SetLWAAuthorizationCredentials(lwaAuthorizationCredentials) .Build();

Résoudre les problèmes liés à un SDK C#

Erreurs IRestRequest : “RestSharp Version=105.0.0.0. Culture=neutral. PublicKevToken=598062e77f915f75 est défini dans un assemblage qui n'est pas référencé. Vous devez ajouter une référence à l'assemblage {{2}}”

Sélectionnez pour développer la réponse. Mettez à jour le package {{0}} vers la version 106.12.0.0. Vérifiez la référence pour vous assurer que la version 106.12 a été correctement mise à jour. Si la version 105.0.0.0 s'affiche toujours, supprimez l'ancienne version de la référence et ajoutez le package 106.12.0.0 manuellement depuis le dossier des packages contenant la bibliothèque client générée.

“Le nom du type ou de l'espace de noms {{0}} est introuvable (vous manque-t-il une directive d'utilisation ou une référence d'assemblage ?)”

Sélectionnez pour développer la réponse.

In some scenarios, even though you have the required version in the NuGet packages for Newtonsoft, it requires manual addition from the package folder in the file system. To resolve this, use the following steps:

  1. In Visual Studio, right-click your generated SDK package and choose Add, then References.

  2. On the references window in the .Net Assembly, choose browse.

  3. Navigate to the generated client library folder in local > packages and add the specific package for Newtonsoft.

“Message : impossible de charger le type de champ SellingPartnerAPI.servicesApi.Client.ApiClient:rateLimiter (3) en raison de : impossible de charger le fichier ou l'assemblage ComposableAsync.Core, Version=1.1.1.0, Culture=neutral, PublicKeyToken=null ou l'une de ses dépendances.”

Sélectionnez pour développer la réponse.

Si vous recevez cette erreur après avoir créé et exécuté votre code, le package de dépendances ComposableAsync.Core a été téléchargé mais n'a pas été inclus comme référence. Assurez-vous d'ajouter manuellement la bibliothèque dll comme référence.

Problèmes de mappage liés aux modèles

Sélectionnez pour développer la réponse.

The ItemAsin model was generated with the JsonObject type, but the required string ItemAttributes requires the JsonObjectAttribute. You can use this command, which uses the Catalog Items API, to import the required mapping for the models :

`java -jar swagger-codegen-cli.jar generate -i catalogItems_2022-04-01.json -l csharp -t sellingpartner-api-aa-csharp\src\Amazon.SellingPartnerAPIAA\resources\swagger-codegen\templates —import-mappings ItemAttributes=Newtonsoft.Json.JsonObjectAttribute —import-mappings ItemAsin=System.string -o catalogItems2022-04-01_import`

HttpRequestHeaders.ToJson() : aucune méthode appropriée à ignorer n'a été trouvée.”

Sélectionnez pour développer la réponse.

Modifiez le mot-clé override avec virtual. Déclarez les méthodes comme virtual afin qu'elles puissent être ignorées.

public virtual string ToJson() { return JsonConvert.SerializeObject(this, Formatting.Indented); }

“Le nom BaseValidate n'existe pas dans le contexte actuel”

Sélectionnez pour développer la réponse.

Supprimez les commentaires des méthodes mentionnées dans la classe :

// IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext) // { // foreach (var x in BaseValidate(validationContext)) // yield return x; // yield break; // }

Cette page vous a-t-elle été utile ?