How to Post e.g. Inventory?

Hello,

Please be patient with me as a hobby programmer.
At the moment I transfer my database from Office Access (Yes I have started with this) to a web based solution by means of APS.net core with c#.
Now I have some difficulties with the API POST at Brickowl. It's easy to GET data from Brickowl - this is successfully implemented.
Can you give me an idea how to POST the data? My apiURI looks like:
https://api.brickowl.com/v1/inventory/create?key=MYKEY&boid=656416&color_id=89&quantity=3&price=120.000&condition=newinventory/create?key=207a4525f55c7707e86efb2752f7cbc68fb1f9a82eec7f75e1bbd067c0541eb8&boid=656416&color_id=89&quantity=3&price=120.000&condition=new

I have tried the same ways I use at Bricklink (with content Json-Formatted), but it does not work.

Any help - and if it's only a small piece - is really appreciated.


Best regards,
Oliver.

Comments

  • 10 Comments sorted by Votes Date Added
  • Your issue may well that POST arguements (variables) have to be handled differently to GET. In GET you can just put it in the URL but that will be ignored for POST.
  • Thank you for the answer Lawrence.
    This was also my idea at the beginning, but the first step has not worked.
    Now I am sitting in a hotel in Cascais, Portugal and I will enjoy a local beer. Hopefully this will help to find my solution. :-)

    Regards,
    Oliver
  • Ohlala, now I receive only error message 403 forbidden.
    I use jsonString with the whole content including key, Encoded UTF8, "application/json".

    Does anybody can share his code (C#) with the Brick Owl API POST method? For your efforts I will activate a 20% voucher in my shop! I guess it's a fair deal, or not?
  • So 403 indicates the key isn’t being sent correctly, I don’t think the arguements should be json though. I would see if you can find code examples for using POST on other APIs.
  • I am struggling with the api-key. I have tried now several ways:
    a) client.DefaultRequestHeaders.Add("key", MYKEY);
    b) formData.Add(new KeyValuePair<string, string>("key", MYKEY));
    HttpContent q = new FormUrlEncodedContent(formData);

    I have also tried in both cases "api-key", "apikey" and "key" like I have found on several pages.
    All the different ways I have found in the web does not work with my key. That means I have to send it in another way - but for this your documentation is unfortunately not completely written.

    If I have solved the issue with the key (which works by the way for the GET requests) I can fix the way with the arguments.

    Do you have any more documentation from your API interface?
  • My main question is the wording for the key in the header as you can see in my examples before.
  • edited March 2018 Vote Up0Vote Down
    I answered about the same by email, but since it's good for answers to be public, here's what your POST should look like:

    printf( "POST /v1/inventory/create HTTP/1.1\r\nHost: api.brickowl.com\r\nContent-Type:
    application/x-www-form-urlencoded\r\nContent-Length: %d\r\nConnection: Keep-Alive\r\n\r\nkey=%s&boid=%ld", content_length, your_brickowl_key, boid_to_create );

    Where content_length would be the length in bytes of what follows "\r\n\r\n", the content.

    Don't pipeline too many updates before the replies start coming in, the API server doesn't like that (BrickSync keeps up to 8 commands "in flight").
  • Stragus, I have just replied - it's working now. My mistake was that I have used as Content-Type "application/json" like it was proposed in the web and how it works with Bricklink. In the moment when I have changed the Content-Type to "application/x-www-form-urlencoded" my code has started to work.

    And in addition here's the C# code how I use it in ASP.net Core:

    var formData = new List<KeyValuePair<string, string>>();
    appUrl = "https://api.brickowl.com/v1/inventory/delete";
    formData.Add(new KeyValuePair<string, string>("key", MY_API_KEY));
    formData.Add(new KeyValuePair<string, string>("external_id", THE_ID_INVENTORY));
    HttpContent q = new FormUrlEncodedContent(formData);
    q.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/x-www-form-urlencoded");

    using (HttpClient client = new HttpClient())
    {
    client.BaseAddress = new Uri(appUrl);

    var result = client.PostAsync(appUrl, q);
    var resultRead = result.Result.Content.ReadAsStringAsync().Result;
    return resultRead;
    }

    In the KeyValuePair has to be the Api-key followed by all other arguments depending on the requirements in the Brick Owl API documentation.


    Have a great time with LEGO or programming or anyhting else :-)

    Regards,
    Oliver.
  • Another comment to the last sentence of Stragus. In ASP.net core you don't have to take care about the "pipeline" with unanswered requests. This is solved from the program with the Async Post Method.
  • > @OliS said:
    > Another comment to the last sentence of Stragus. In ASP.net core you don't have to take care about the "pipeline" with unanswered requests. This is solved from the program with the Async Post Method.

    No matter what API you use, you still have to care or set how many requests are pipelined over the socket. Unless not using pipelining at all, but then it's a little slow.

    I'm from the field of high performance computing, and I'm still baffled how web servers can't handle hundreds of thousands pipelined requests per second, but rather something like... eight. ;)
Sign In or Register to comment.