0

I have a product with some size-variations.

For example root item has sku 20159DA2 and children have for sku 20159DA2-S, 20159DA2-XS, etc

I want to call the method bulkUpdatePriceQuantity but it gives me Bad Request telling me the sku doesn't exists.

Here the example of the json I'm sending to Ebay

{
"requests": [{
    "offers": [{
        "availableQuantity": 1,
        "offerId": "115388226132",
        "price": {
            "currency": "EUR",
            "value": "69.99"
        }
    }],
    "shipToLocationAvailability": {
        "quantity": 1
    },
    "sku": "20159DA2-XS"
}, {
    "offers": [{
        "availableQuantity": 1,
        "offerId": "115388226149",
        "price": {
            "currency": "EUR",
            "value": "89.99"
        }
    }],
    "shipToLocationAvailability": {
        "quantity": 1
    },
    "sku": "20302DA2-S"
}, {
    "offers": [{
        "availableQuantity": 1,
        "offerId": "115388226149",
        "price": {
            "currency": "EUR",
            "value": "89.99"
        }
    }],
    "shipToLocationAvailability": {
        "quantity": 1
    },
    "sku": "20302DA2-XS"
}]

}

the beam that is coming to me is that I can not use this method for variations. But if so is there any other method I can use to update just the change quantities?


--------USING ReviseFixedPriceItem-------------------

the json I have is

{
        "RequesterCredentials": {
            "eBayAuthToken": ""
        },
        "Item": {
            "ItemID": "115809802256",
            "Variations": {
                "Variation": [{
                    "SKU": "STALLION_0",
                    "Quantity": 4
                }]
            }
        }
       }

The HttpPost is

 using (var client = new HttpClient())
        {
            client.DefaultRequestHeaders.Add("Authorization", "TOKEN " + EBAY_TOKEN);

            client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");



            client.DefaultRequestHeaders.Add("X-EBAY-C-MARKETPLACE-ID", "EBAY_IT");

            client.DefaultRequestHeaders.Add("Accept", "application/json");
            client.DefaultRequestHeaders.Accept.Add(
                   new MediaTypeWithQualityHeaderValue("application/json"));

            System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            var url = $"https://api.ebay.com/wsapi?callname=ReviseFixedPriceItem";

            string _jsonContent = JsonConvert.SerializeObject(json);
            HttpContent _httpContent = new StringContent(_jsonContent, Encoding.UTF8, HTTPManager.HTTP_POST_CONTENT_TYPE_JSON);

            System.Net.Http.HttpResponseMessage response = client.PostAsync(url, _httpContent).Result;
            response.EnsureSuccessStatusCode();
            var resp = response.Content.ReadAsStringAsync().Result;
 }

-----------------USING XML---------------------------

<?xml version="1.0" encoding="UTF-8"?>
<ReviseFixedPriceItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
 <ErrorLanguage>it_IT</ErrorLanguage>
 <WarningLevel>Low</WarningLevel>
 <Item>
  <ItemID>115711360327</ItemID>
  <Variations>
     <Variation>
        <SKU>07000-129-M_39</SKU>
        <Quantity>0</Quantity>
     </Variation>
     <Variation>
        <SKU>07000-129-M_40</SKU>
        <Quantity>1</Quantity>
     </Variation>
     <Variation>
        <SKU>07000-129-M_41</SKU>
        <Quantity>2</Quantity>
     </Variation>
     <Variation>
        <SKU>07000-129-M_42</SKU>
        <Quantity>2</Quantity>
     </Variation>
     <Variation>
        <SKU>07000-129-M_43</SKU>
        <Quantity>3</Quantity>
     </Variation>
     <Variation>
        <SKU>07000-129-M_44</SKU>
        <Quantity>1</Quantity>
     </Variation>
     <Variation>
        <SKU>07000-129-M_45</SKU>
        <Quantity>1</Quantity>
     </Variation>
     <Variation>
        <SKU>07000-129-M_46</SKU>
        <Quantity>0</Quantity>
     </Variation>
     <Variation>
        <SKU>07000-129-M_47</SKU>
        <Quantity>0</Quantity>
     </Variation>
  </Variations>
 </Item>

and use HTTP POST with xml as parameter I get status OK but the response is Ebay Official DateTime, and I need to call ReviseFixedPriceItem

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.ebay.com/ws/api.dll");
        byte[] bytes;
        bytes = System.Text.Encoding.ASCII.GetBytes(xml);
        request.ContentType = "text/xml; encoding='utf-8'";
        request.ContentLength = bytes.Length;
        request.Method = "POST";
        Stream requestStream = request.GetRequestStream();
        requestStream.Write(bytes, 0, bytes.Length);
        requestStream.Close();
        HttpWebResponse response;
        response = (HttpWebResponse)request.GetResponse();
        if (response.StatusCode == System.Net.HttpStatusCode.OK)
        {
            Stream responseStream = response.GetResponseStream();
            string responseStr = new StreamReader(responseStream).ReadToEnd();
            return responseStr;
        }
Martina
  • 1,852
  • 8
  • 41
  • 78

2 Answers2

2

Checking the code and the issue about the SKU doesn't exist, it appears that you are attempting to use the bulkUpdatePriceQuantity method in eBay, but it doesn't support variations, because basically this method is designed for updating price and quantity information for individual items, not variations.

For updating the quantity of variations, eBay provides a separate method called ReviseFixedPriceItem instead, which allows you to update specific variation details, including quantity, price, and other attributes.

So I think you will need to use the Trading API to make requests for revising item details.

Anyway, try this JSON payload for revising the quantity of a variation using the ReviseFixedPriceItem method, an example could be:

In this example, you need to replace "YOUR_AUTH_TOKEN" with your actual eBay authorization token and "YOUR_ITEM_ID" with the ID of the item you want to update.

json

{
  "RequesterCredentials": {
    "eBayAuthToken": "YOUR_AUTH_TOKEN"
  },
  "Item": {
    "ItemID": "YOUR_ITEM_ID",
    "Variations": {
      "Variation": [
        {
          "SKU": "20159DA2-XS",
          "Quantity": 5
        },
        {
          "SKU": "20302DA2-S",
          "Quantity": 10
        },
        {
          "SKU": "20302DA2-XS",
          "Quantity": 8
        }
      ]
    }
  }
}

Something like that could solve the internal server error:


using (var client = new HttpClient())

{
    client.DefaultRequestHeaders.Add("Authorization", "TOKEN " + EBAY_TOKEN);
    client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
    client.DefaultRequestHeaders.Add("X-EBAY-C-MARKETPLACE-ID", "EBAY_IT");
    client.DefaultRequestHeaders.Add("Accept", "application/json");

    System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    var url = "https://api.ebay.com/ws/api.dll";

    string _jsonContent = JsonConvert.SerializeObject(json);
    HttpContent _httpContent = new StringContent(_jsonContent, Encoding.UTF8, "application/json");

    // Console.WriteLine("Sending request to eBay API...");
    // Console.WriteLine("Request URL: " + url);
    // Console.WriteLine("Request Payload: " + _jsonContent);

    System.Net.Http.HttpResponseMessage response = client.PostAsync(url, _httpContent).Result;
    response.EnsureSuccessStatusCode();

    // Console.WriteLine("Received response from eBay API...");

    var resp = response.Content.ReadAsStringAsync().Result;

    // Console.WriteLine("Response Content: " + resp);
}

Note that I included a little debbuger (console.WriteLine) to print out relevant information during the execution, just uncomment it to check the status of the code.

custom header constants like "HTTPManager.HTTP_POST_CONTENT_TYPE_JSON" and "EBAY_TOKEN" with your actual eBay authorization token and any custom constants used in the code have the correct values assigned to them, I think it should work, because I am not trying to run the code, so I hope.

In the Ebay official documentation, they refer the construct of XML payload for revising the item variation quantities, a simple example would be:

<?xml version="1.0" encoding="UTF-8"?>
<ReviseFixedPriceItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
  <RequesterCredentials>
    <eBayAuthToken>YOUR_AUTH_TOKEN</eBayAuthToken>
  </RequesterCredentials>
  <Item>
    <ItemID>YOUR_ITEM_ID</ItemID>
    <Variations>
      <Variation>
        <SKU>20159DA2-XS</SKU>
        <Quantity>5</Quantity>
      </Variation>
      <Variation>
        <SKU>20302DA2-S</SKU>
        <Quantity>10</Quantity>
      </Variation>
      <Variation>
        <SKU>20302DA2-XS</SKU>
        <Quantity>8</Quantity>
      </Variation>
    </Variations>
  </Item>
</ReviseFixedPriceItemRequest>

Using the constructed XML payload, you can send an HTTP POST request to the url endpoint with the payload as the request body to perform the ReviseFixedPriceItem call.

Gonzalo Cugiani
  • 459
  • 2
  • 15
  • Thank you, tomorrow I’m going to try this solution and I solo let you know if it works. It appears wonderful – Martina May 30 '23 at 04:20
  • You're welcome @Martina, yes I hope too, have a good night and let me know! – Gonzalo Cugiani May 30 '23 at 19:51
  • I'm getting Internal Server Error, I' going to update my question – Martina May 31 '23 at 08:59
  • Ok, let me check and modify my answer, maybe we got it. – Gonzalo Cugiani May 31 '23 at 16:23
  • Ok like this it not return Internal Server Error but I thing the url is incorrect because the response status is OK but the response.Content.ReadAsStringAsync().Result is Ebay getDate response, so it is not calling the ReviseFixedPrice method. – Martina Jun 01 '23 at 07:38
  • You should use the appropriate endpoint for the ReviseFixedPriceItem call, check the URL to use the correct endpoint ... var url = "https://api.ebay.com/ws/api.dll"; – Gonzalo Cugiani Jun 01 '23 at 22:31
  • -i know, but I'm not able to find the correct endpoint url. https://developer.ebay.com/DevZone/XML/docs/Reference/eBay/ReviseFixedPriceItem.html – Martina Jun 02 '23 at 08:15
  • I was checking the ebay documentation and they mentioned the use of XML, I added a little snippet. – Gonzalo Cugiani Jun 03 '23 at 12:17
0

Finally I solved with XML and request.Headers with CallName


-----------------USING XML---------------------------

<?xml version="1.0" encoding="UTF-8"?>
<ReviseFixedPriceItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<ErrorLanguage>it_IT</ErrorLanguage>
<WarningLevel>Low</WarningLevel>
<RequesterCredentials>
  <eBayAuthToken>EBAY_TOKEN</eBayAuthToken>
</RequesterCredentials>
<Item>
  <ItemID>115711360327</ItemID>
  <Variations>
     <Variation>
        <SKU>07000-129-M_39</SKU>
        <Quantity>0</Quantity>
     </Variation>
     ...
   </Variations>
  </Item>
</ReviseFixedPriceItemRequest>

and use HTTP POST with xml as parameter

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.ebay.com/ws/api.dll");
            byte[] bytes;
            bytes = System.Text.Encoding.ASCII.GetBytes(xml);
            request.ContentType = "text/xml; encoding='utf-8'";
            request.ContentLength = bytes.Length;
            request.Method = "POST";                
            request.Headers.Add("X-EBAY-API-CALL-NAME", "ReviseFixedPriceItem");
            request.Headers.Add("X-EBAY-API-SITEID", "101");
            request.Headers.Add("X-EBAY-API-COMPATIBILITY-LEVEL", "613");
            request.Headers.Add("X-EBAY-API-APP-NAME", MY_EBAY-API-APP-NAME);
            request.Headers.Add("X-EBAY-API-DEV-NAME", MY_API-DEV-NAME);
            request.Headers.Add("X-EBAY-API-CERT-NAME", MY_API-CERT-NAME);
            
            Stream requestStream = request.GetRequestStream();
            requestStream.Write(bytes, 0, bytes.Length);
            requestStream.Close();
            HttpWebResponse response;
            response = (HttpWebResponse)request.GetResponse();
            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                Stream responseStream = response.GetResponseStream();
                string responseStr = new StreamReader(responseStream).ReadToEnd();
                return responseStr;
            }
Martina
  • 1,852
  • 8
  • 41
  • 78