Skip to content

Commit 1be5c28

Browse files
committed
2 parents 06f7102 + 5b2bb27 commit 1be5c28

13 files changed

+497
-7
lines changed

README.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,104 @@ var processingReport = await amazonConnection.Feed.GetJsonFeedDocumentProcessing
530530

531531
```
532532

533+
#### Website authorization workflow.
534+
```CSharp
535+
[HttpGet("AuthorizeAmazon")]
536+
public async Task<IActionResult> AuthorizeAmazon()
537+
{
538+
// Step 2-5 of the website authorization workflow.
539+
540+
// Step 2-3: Amazon calls our log-in URI with amazon_callback_uri.
541+
var amazonCallbackUri = Request.Query["amazon_callback_uri"].ToString();
542+
if (!string.IsNullOrEmpty(amazonCallbackUri))
543+
{
544+
var amazonState = Request.Query["amazon_state"].ToString();
545+
var version = configuration["FikaAmazonAPI:AuthorizeVersion"];
546+
var redirectUri = configuration["FikaAmazonAPI:AmazonCallbackUri"];
547+
548+
var generatedState = Guid.NewGuid().ToString("N");
549+
Response.Cookies.Append("amazon_oauth_state", generatedState, new CookieOptions
550+
{
551+
HttpOnly = true,
552+
Secure = true,
553+
SameSite = SameSiteMode.Lax,
554+
Expires = DateTimeOffset.UtcNow.AddMinutes(5)
555+
});
556+
557+
var query = new Dictionary<string, string?>
558+
{
559+
["redirect_uri"] = redirectUri,
560+
["amazon_state"] = amazonState,
561+
["state"] = generatedState
562+
};
563+
564+
if (!string.IsNullOrEmpty(version))
565+
{
566+
query["version"] = version;
567+
}
568+
569+
Response.Headers["Referrer-Policy"] = "no-referrer";
570+
var redirectUrl = QueryHelpers.AddQueryString(amazonCallbackUri, query!);
571+
return Redirect(redirectUrl);
572+
}
573+
574+
// Step 4-5: Amazon redirects back to our redirect_uri with authorization code.
575+
var state = Request.Query["state"].ToString();
576+
var sellingPartnerId = Request.Query["selling_partner_id"].ToString();
577+
var mwsAuthToken = Request.Query["mws_auth_token"].ToString();
578+
var code = Request.Query["spapi_oauth_code"].ToString();
579+
580+
var storedState = Request.Cookies["amazon_oauth_state"];
581+
if (string.IsNullOrEmpty(state) || storedState != state)
582+
{
583+
return BadRequest("Invalid state");
584+
}
585+
586+
Response.Cookies.Delete("amazon_oauth_state");
587+
588+
if (string.IsNullOrEmpty(code))
589+
{
590+
return BadRequest("Missing spapi_oauth_code");
591+
}
533592

593+
var clientId = configuration["FikaAmazonAPI:ClientId"];
594+
var clientSecret = configuration["FikaAmazonAPI:ClientSecret"];
595+
var callbackUri = configuration["FikaAmazonAPI:AmazonCallbackUri"];
596+
597+
using var httpClient = new HttpClient();
598+
var form = new FormUrlEncodedContent(new Dictionary<string, string>
599+
{
600+
["grant_type"] = "authorization_code",
601+
["code"] = code,
602+
["client_id"] = clientId ?? string.Empty,
603+
["client_secret"] = clientSecret ?? string.Empty,
604+
["redirect_uri"] = callbackUri ?? string.Empty
605+
});
606+
607+
using var response = await httpClient.PostAsync("https://api.amazon.com/auth/o2/token", form);
608+
var responseBody = await response.Content.ReadAsStringAsync();
609+
if (!response.IsSuccessStatusCode)
610+
{
611+
return BadRequest(responseBody);
612+
}
613+
614+
using var document = JsonDocument.Parse(responseBody);
615+
var refreshToken = document.RootElement.GetProperty("refresh_token").GetString();
616+
var accessToken = document.RootElement.GetProperty("access_token").GetString();
617+
618+
return Json(new
619+
{
620+
state,
621+
selling_partner_id = sellingPartnerId,
622+
mws_auth_token = mwsAuthToken,
623+
refresh_token = refreshToken,
624+
access_token = accessToken
625+
});
626+
}
627+
628+
```
629+
630+
534631
#### Feed Submit for change Quantity
535632
```CSharp
536633
ConstructFeedService createDocument = new ConstructFeedService("{SellerID}", "1.02");
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* Selling Partner API for Pricing
3+
*
4+
* The Selling Partner API for Pricing helps you programmatically retrieve product pricing and offer information for Amazon Marketplace products.
5+
*
6+
* OpenAPI spec version: v0
7+
*
8+
* Generated by: https://github.com/swagger-api/swagger-codegen.git
9+
*/
10+
11+
using Newtonsoft.Json;
12+
using System;
13+
using System.Collections.Generic;
14+
using System.ComponentModel.DataAnnotations;
15+
using System.IO;
16+
using System.Runtime.Serialization;
17+
using System.Text;
18+
19+
namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ListingsItems
20+
{
21+
/// <summary>
22+
/// AsinIdentifier
23+
/// </summary>
24+
[DataContract]
25+
public partial class AsinIdentifier : IEquatable<AsinIdentifier>, IValidatableObject
26+
{
27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="AsinIdentifier" /> class.
29+
/// </summary>
30+
[JsonConstructorAttribute]
31+
public AsinIdentifier() { }
32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="AsinIdentifier" /> class.
34+
/// </summary>
35+
/// <param name="marketplaceId">A marketplace identifier. Identifies the Amazon marketplace for the listings item.</param>
36+
/// <param name="asin">Amazon Standard Identification Number (ASIN) of the listings item.</param>
37+
public AsinIdentifier(string marketplaceId = default(string), string asin = default(string))
38+
{
39+
40+
}
41+
42+
/// <summary>
43+
/// A marketplace identifier. Identifies the Amazon marketplace for the listings item.
44+
/// </summary>
45+
/// <value>A marketplace identifier. Identifies the Amazon marketplace for the listings item.</value>
46+
[DataMember(Name = "marketplaceId", EmitDefaultValue = false)]
47+
public string MarketplaceId { get; set; }
48+
49+
/// <summary>
50+
/// Amazon Standard Identification Number (ASIN) of the listings item.
51+
/// </summary>
52+
/// <value>Amazon Standard Identification Number (ASIN) of the listings item.</value>
53+
[DataMember(Name = "asin", EmitDefaultValue = false)]
54+
public string Asin { get; set; }
55+
56+
/// <summary>
57+
/// Returns the string presentation of the object
58+
/// </summary>
59+
/// <returns>String presentation of the object</returns>
60+
public override string ToString()
61+
{
62+
var sb = new StringBuilder();
63+
sb.Append("class AsinIdentifier {\n");
64+
sb.Append(" MarketplaceId: ").Append(MarketplaceId).Append("\n");
65+
sb.Append(" Asin: ").Append(Asin).Append("\n");
66+
sb.Append("}\n");
67+
return sb.ToString();
68+
}
69+
70+
/// <summary>
71+
/// Returns the JSON string presentation of the object
72+
/// </summary>
73+
/// <returns>JSON string presentation of the object</returns>
74+
public string ToJson()
75+
{
76+
return JsonConvert.SerializeObject(this, Formatting.Indented);
77+
}
78+
79+
/// <summary>
80+
/// Returns true if objects are equal
81+
/// </summary>
82+
/// <param name="input">Object to be compared</param>
83+
/// <returns>Boolean</returns>
84+
public override bool Equals(object input)
85+
{
86+
return this.Equals(input as AsinIdentifier);
87+
}
88+
89+
/// <summary>
90+
/// Returns true if AsinIdentifier instances are equal
91+
/// </summary>
92+
/// <param name="input">Instance of AsinIdentifier to be compared</param>
93+
/// <returns>Boolean</returns>
94+
public bool Equals(AsinIdentifier input)
95+
{
96+
if (input == null)
97+
return false;
98+
99+
return
100+
(
101+
this.MarketplaceId == input.MarketplaceId ||
102+
(this.MarketplaceId != null &&
103+
this.MarketplaceId.Equals(input.MarketplaceId))
104+
) &&
105+
(
106+
this.Asin == input.Asin ||
107+
(this.Asin != null &&
108+
this.Asin.Equals(input.Asin))
109+
);
110+
}
111+
112+
/// <summary>
113+
/// Gets the hash code
114+
/// </summary>
115+
/// <returns>Hash code</returns>
116+
public override int GetHashCode()
117+
{
118+
unchecked // Overflow is fine, just wrap
119+
{
120+
int hashCode = 41;
121+
if (this.MarketplaceId != null)
122+
hashCode = hashCode * 59 + this.MarketplaceId.GetHashCode();
123+
if (this.Asin != null)
124+
hashCode = hashCode * 59 + this.Asin.GetHashCode();
125+
return hashCode;
126+
}
127+
}
128+
129+
/// <summary>
130+
/// To validate all properties of the instance
131+
/// </summary>
132+
/// <param name="validationContext">Validation context</param>
133+
/// <returns>Validation Result</returns>
134+
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
135+
{
136+
yield break;
137+
}
138+
}
139+
140+
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* Selling Partner API for Listings Items
3+
*
4+
* The Selling Partner API for Listings Items (Listings Items API) provides programmatic access to selling partner listings on Amazon. Use this API in collaboration with the Selling Partner API for Product Type Definitions, which you use to retrieve the information about Amazon product types needed to use the Listings Items API. For more information, see the [Listings Items API Use Case Guide](doc:listings-items-api-v2021-08-01-use-case-guide).
5+
*
6+
* OpenAPI spec version: 2021-08-01
7+
*
8+
* Generated by: https://github.com/swagger-api/swagger-codegen.git
9+
*/
10+
11+
using System;
12+
using System.IO;
13+
using System.Text;
14+
using System.Collections.Generic;
15+
using System.Runtime.Serialization;
16+
using Newtonsoft.Json;
17+
using System.ComponentModel.DataAnnotations;
18+
19+
namespace FikaAmazonAPI.AmazonSpApiSDK.Models.ListingsItems
20+
{
21+
/// <summary>
22+
/// Buyer segment or program this offer is applicable to.
23+
/// </summary>
24+
[DataContract]
25+
public partial class Audience : IEquatable<Audience>, IValidatableObject
26+
{
27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="Audience" /> class.
29+
/// </summary>
30+
[JsonConstructorAttribute]
31+
protected Audience() { }
32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="Audience" /> class.
34+
/// </summary>
35+
/// <param name="value">Name of the audience an offer is applicable to.</param>
36+
/// <param name="displayName">Localized display name for the audience.</param>
37+
public Audience(OfferAudienceEnum? value = default(OfferAudienceEnum?), string displayName = default(string))
38+
{
39+
40+
}
41+
42+
/// <summary>
43+
/// Name of the audience an offer is applicable to.
44+
/// </summary>
45+
/// <value>Name of the audience an offer is applicable to.</value>
46+
[DataMember(Name= "value", EmitDefaultValue=false)]
47+
public OfferAudienceEnum? Value { get; set; }
48+
49+
/// <summary>
50+
/// Localized display name for the audience.
51+
/// </summary>
52+
/// <value>Localized display name for the audience.</value>
53+
[DataMember(Name= "displayName", EmitDefaultValue=false)]
54+
public string DisplayName { get; set; }
55+
56+
/// <summary>
57+
/// Returns the string presentation of the object
58+
/// </summary>
59+
/// <returns>String presentation of the object</returns>
60+
public override string ToString()
61+
{
62+
var sb = new StringBuilder();
63+
sb.Append("class Audience {\n");
64+
sb.Append(" Value: ").Append(Value).Append("\n");
65+
sb.Append(" DisplayName: ").Append(DisplayName).Append("\n");
66+
sb.Append("}\n");
67+
return sb.ToString();
68+
}
69+
70+
/// <summary>
71+
/// Returns the JSON string presentation of the object
72+
/// </summary>
73+
/// <returns>JSON string presentation of the object</returns>
74+
public virtual string ToJson()
75+
{
76+
return JsonConvert.SerializeObject(this, Formatting.Indented);
77+
}
78+
79+
/// <summary>
80+
/// Returns true if objects are equal
81+
/// </summary>
82+
/// <param name="input">Object to be compared</param>
83+
/// <returns>Boolean</returns>
84+
public override bool Equals(object input)
85+
{
86+
return this.Equals(input as Audience);
87+
}
88+
89+
/// <summary>
90+
/// Returns true if Audience instances are equal
91+
/// </summary>
92+
/// <param name="input">Instance of Audience to be compared</param>
93+
/// <returns>Boolean</returns>
94+
public bool Equals(Audience input)
95+
{
96+
if (input == null)
97+
return false;
98+
99+
return
100+
(
101+
this.Value == input.Value ||
102+
(this.Value != null &&
103+
this.Value.Equals(input.Value))
104+
) &&
105+
(
106+
this.DisplayName == input.DisplayName ||
107+
(this.DisplayName != null &&
108+
this.DisplayName.Equals(input.DisplayName))
109+
);
110+
}
111+
112+
/// <summary>
113+
/// Gets the hash code
114+
/// </summary>
115+
/// <returns>Hash code</returns>
116+
public override int GetHashCode()
117+
{
118+
unchecked // Overflow is fine, just wrap
119+
{
120+
int hashCode = 41;
121+
if (this.Value != null)
122+
hashCode = hashCode * 59 + this.Value.GetHashCode();
123+
if (this.DisplayName != null)
124+
hashCode = hashCode * 59 + this.DisplayName.GetHashCode();
125+
return hashCode;
126+
}
127+
}
128+
129+
/// <summary>
130+
/// To validate all properties of the instance
131+
/// </summary>
132+
/// <param name="validationContext">Validation context</param>
133+
/// <returns>Validation Result</returns>
134+
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
135+
{
136+
yield break;
137+
}
138+
}
139+
140+
}

0 commit comments

Comments
 (0)