Skip to content

PiotrFerenc/Allegro-api-rest-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Allegro api rest client

Połączenie:

  • FluentValidation
  • MediatR
  • Autofac
Authorization
var clientId = "Client ID z zarejestrowanej aplikacji: https://apps.developer.allegro.pl/";
var clientSecret = "Client Secret z zarejestrowanej aplikacji: https://apps.developer.allegro.pl/";
var base64Key = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{clientId}:{clientSecret}"));

var allegroApi = new AllegroRestClient();

var data = await allegroApi.Query(new GetVerificationUriCompleteCommand()
{
    AuthKey = base64Key,
    ClientId = clientId
});

//open browser with data.url

var result = await allegroApi.Query(new CheckAccountConfirmationCommand()
{
    Authorization = base64Key,
    DeviceCodeId = data.deviceCode
});

var authorization = result.deviceAuthToken.access_token;

Pobieranie Seller.id

    var token = new JWT.Builder.JwtBuilder().Decode<Token>(authorization);
    var sellerId = token.user_name

Pobieranie szczegółów oferty:

https://developer.allegro.pl/documentation/#operation/getOfferUsingGET

var result = await allegroApi.Query(new GetOfferByIdQuery()
{
    OfferId = "10862116958",
    Authorization = authorization
});                

Dziennik zdarzeń w ofertach sprzedawcy:

https://developer.allegro.pl/documentation/#operation/getOfferEvents

var result = await allegroApi.Query(new GetOfferEventsQuery()
{
    Type = GetOfferEventsQuery.OfferEventType.OFFER_ACTIVATED,
    Authorization = authorization,
    Limit = 1000,
    From = "ID-EVENTU"
});

Jak pobrać moje oferty w REST API

https://developer.allegro.pl/documentation/#operation/searchOffersUsingGET

var result = await allegroApi.Query(new GetAllOffersQuery()  
{  
    Authorization = authorization,  
    PublicationStatus = PublicationStatus.Active  
});

Pobieranie metod dostawy

https://developer.allegro.pl/documentation/#operation/getListOfDeliveryMethodsUsingGET

var result = await allegroApi.Query(new GetDeliveryMethodsQuery()
{
    Authorization = authorization,
});

Pobieranie cenników dostaw

https://developer.allegro.pl/news/2018-08-14-cenniki_dostawy/#list

var result = await allegroApi.Query(new GetSellerShippingRatesQuery()
{
    Authorization = authorization,
    SellerId = "123456"
 });

Warunki reklamacji

var result = await allegroApi.Query(new GetImpliedWarrantiesQuery()
{
    Authorization = authorization,
    SellerId = "123456"
});

Warunki zwrotów

var result = await allegroApi.Query(new GetReturnPoliciesQuery()
{
    Authorization = authorization,
    SellerId = "123456"
});

Informacje o gwarancji

var result = await allegroApi.Query(new GetWarrantiesQuery()
{
    Authorization = authorization,
    SellerId = "123456"
});

Punkty odbioru osobistego

var pos = await allegroApi.Query(new GetPosQuery()
{
    Authorization = authorization,
    sellerId = "123456"
});

Wystawianie ofert

var auth = "auth-code";
                
var offer = await allegroApi.Query(new OfferByIdQuery()
{
    Authorization = authorization,
    OfferId = "1234567890"
});

Console.WriteLine(offer.Name);
                
var result = await allegroApi.Query(new CreateDraftOfferCommand()
{
    Authorization = authorization,
    Offer = new NewOffer(offer)
});

Console.WriteLine(result); //<-- draft id

Aktualizacja oferty

var auth = "auth-code";

var offer = await allegroApi.Query(new OfferByIdQuery()
{
    Authorization = authorization,
    OfferId = "1234567890"
});

var result = await allegroApi.Query(new UpdateOfferCommand()
{
    Authorization = authorization,
    Offer = offer
});

Publikowanie ofert

var result = await allegroApi.Query(new PublishOffersCommand()
{
    Authorization = authorization,
    Offers = new List<OfferId>()
    {
        new OfferId("11124109817")
    }
});

Pobieranie produktów

*Produkty pobierane są wegług nazwy. Dodatkowo wybierony jest najpodobniejszy za pomocą algorytmu Levenshtein distance. *

var products = await allegroApi.Query(new GetProductsByNameQuery()
{
    Authorization = authorization,
    Name = "Łożysko stożkowe ZVL 32315A"
});

Console.WriteLine("Łożysko stożkowe ZVL 32315A" );
Console.WriteLine(products.bestProductByName.Name);
Łożysko stożkowe ZVL 32315A
ŁOŻYSKO STOŻKOWE ZVL 32315 A 75x160x58

Upload zdjęć z dysku

var file = File.ReadAllBytes(@"C:\image.png");
var link = await allegroApi.Query(new UploadImageCommand()
{
    Authorization = authorization,
    File = file
});

PS: NIE MA NAPISANYCH TESTÓW

About

Allegro Rest API Client c# .net

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages