Inhalte aufrufen

Profilbild

Having some trouble with the web api


  • Bitte melden Sie sich an, um eine Antwort zu verfassen.
3 Antworten zu diesem Thema

#1 altmoola

altmoola

    Advanced Member

  • Members
  • 41 Beiträge

Geschrieben: 23 May 2020 - 00:18

What is the proper way to get a product using the Web Api (v3.2.1)? I thought it would be something like these but they don't work:

 

/odata/v1/Products(608)/

/odata/v1/Products(608)/Product

/odata/v1/Products/608

/odata/v1/GetProduct(608)

/odata/v1/Products/GetProduct(608)

/odata/v1/Products?Id=608

 

Not really sure what's going on, since these work:

 

/odata/v1/Products(608)/CountryOfOrigin

/odata/v1/Products(608)/DeliveryTime

/odata/v1/Products(567)/QuantityUnit

 

And these don't work (error 400):

 

/odata/v1/Products(608)/ProductManufacturers

/odata/v1/Products(608)/ProductCategories

/odata/v1/Products(567)/ProductVariantAttributeCombinations

/odata/v1/Products(608)/Manufacturers

/odata/v1/Products(608)/Categories

/odata/v1/Products(567)/VariantAttributeCombinations

 

Code:

string publicKey = "publicKey";
string secretKey = "secretKey";
string method = "get";
string accept = "application/json, text/javascript, text/html, application/xhtml+xml, application/xml;q=0.9,image/webp,image/apng,*/*";
string timestamp = DateTime.UtcNow.ToString("o");
string url = this.textBox1.Text;

var uri = new Uri(url);     // decode url
if (uri.Query != null && uri.Query.Length > 0)
{
    url = string.Concat(uri.GetLeftPart(UriPartial.Path), HttpUtility.UrlDecode(uri.Query));
}

var messageRepresentation = string.Join("\n",
    method.ToLower(),
    "",
    accept.ToLower(),
    url.ToLower(),
    timestamp,
    publicKey.ToLower()
);

var signature = CreateSignature(secretKey, messageRepresentation);
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = method;
request.UserAgent = "My shopping data consumer v.1.0";
request.Accept = accept;
request.Headers.Add("Accept-Charset", "UTF-8");
request.Headers.Add("SmartStore-Net-Api-PublicKey", publicKey);
request.Headers.Add("SmartStore-Net-Api-Date", timestamp);
request.Headers.Add("Authorization", "SmNetHmac1 " + signature);

HttpWebResponse webResponse = null;
string response = null;

try
{
    webResponse = request.GetResponse() as HttpWebResponse;
    using (var reader = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8))
    {
        response = reader.ReadToEnd();
    }
}
catch (Exception ex)
{
    this.textBox2.Text = ex.ToString();
}
finally
{
    if (webResponse != null)
    {
        this.textBox2.Text = response;

        webResponse.Close();
        webResponse.Dispose();
    }
}


#2 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3541 Beiträge

Geschrieben: 25 May 2020 - 14:41

/odata/v1/Products(608)
 
400 sounds like a client code issue. Accept type is JSON (default) or XML. But probably other reason.

Schöne Grüße aus Düsseldorf,
Marcus Gesing


#3 altmoola

altmoola

    Advanced Member

  • Members
  • 41 Beiträge

Geschrieben: 25 May 2020 - 16:02

I get a 500 error with that URL. Does a more detailed error message get logged somewhere on the server?



#4 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3541 Beiträge

Geschrieben: 25 May 2020 - 20:40

No probably not, but if so, it should be in the backend log list.


Schöne Grüße aus Düsseldorf,
Marcus Gesing