[SOLVED] Upload timestamped data

Hello, I am trying to upload a set of data with timestamps as shown here:
https://docs.blynk.io/en/blynk.cloud/upload-set-of-data-with-timestamps-api

I tried to do it with Postman, but I get an “unknown content type” error.

Postman adds by default the application/json header in Content Type, so I was wondering if there is something wrong with the body.

Thanks,
Dimitris

Hello. The content should be an array of arrays (points):

[[ts,value]]

That’s not what the documentation says…

Entry Format

Single entry format: [timestamp, value] The full body is the array of entries:[[timestamp1, value1], [timestamp2, value2]]

Pete.

2 Likes

Thanks for the quick reply. I tried it but I still get the same result:

I am sure that my token is correct, because I can successfully run the Get Datastream Value (Get Datastream Value - Blynk Documentation).

Thanks,
Dimitris

It’s working fine.

In that case, that’s mean that you don’t have “content-type” header. Please check “headers” section and make sure you have the “Content-Type” header.

I mean that “[timestamp, value]” is a single entry. But agree, it may confuse. Fixed.

Sorry again for bothering but still no luck. I have attached below a few images (stitched into one, because I am not allowed to upload more).:

As you can see:

  • I use the “https://fra1.blynk.cloud” server
  • I have created the v19 virtual pin that accepts integers from 0 to 1000
  • I have the Content-Type header set to application/json (actually Postman does this by default)
  • As token, I use my device’s auth token
  • The body is in the form as designated in the documentation.

My apologies if this sounds weird, but we would like to assess this approach ASAP, in order to proceed updating our device’s firmware.

In case you have any other hints, kindly let me know.

Thanks,
Dimitris

Thanks, but for me as mentioned below, still no luck, so I posted as many details as possible, just in case it is visible what I am doing wrong… :frowning:

Thank you,
Dimitris

@dtheodor79 please try to manually add the header. It’s for sure something with Content-Type header. Here is the sever code:

public BlynkPostRequestDecoder(HttpRequest request) {
    String contentType = request.headers().get(HttpHeaderNames.CONTENT_TYPE);
    if (contentType == null) {
        throw new RuntimeException("No content type provided.");
    }

    //split headers like "application/json;encoding=utf8"
    if (contentType.contains(";")) {
        contentType = contentType.split(";")[0];
    }

    switch (contentType) {
        case APPLICATION_FORM_URLENCODED :
            this.decoder = new HttpPostRequestDecoder(request);
            break;
        case APPLICATION_JSON :
            if (request instanceof HttpContent) {
                this.bodyData = ((HttpContent) request).content();
            } else {
                throw new RuntimeException("Unexpected http request");
            }
            break;
        default :
            throw new RuntimeException("Unknown content type");
    }
}

Postman is not always works as expected. Happens all the time. So it would be better to explicitly add Content-Type header.

I’ve been trying to reproduce this and I can’t.

If I un-check the content-Type in headers then I get the “No content type provided.” error…

image

but that’s not the same error that @dtheodor79 is seeing. He’s getting the switch/case default catch-all of “Unknown content type”.

Pete.

You are right, Postman does not always work as expected…

The moment I added myself the Content-Type field, it worked.

Once again, thank you for your fast reply and support!
Dimitris

Eventually it was Postman’s fault, since the Content-Type header was not there (even though it looked that it was!). So when I added it, it worked!

1 Like

Glad it worked. It’s a funny thing, I just was using a Postman a few days ago and had another trouble with it when it was adding some headers due to which my request was rejected with 3-d party service. cURL solved my issue.

Sometimes postman creates more problems than it solves :slight_smile: .

2 Likes