chemokita13 / beReal-api

A not official BeReal rest API in wich you can get all posts info, comment, upload a post...
https://berealapi.fly.dev
78 stars 5 forks source link

Caption are no longer supported #10

Open Kan-A-Pesh opened 1 year ago

Kan-A-Pesh commented 1 year ago

When I make the api call to post/upload/data endpoint I get a 400 error. And when I try making the api call directly to the BeReal API, I get the same error with the following body:

{
    "error": "Bad Request",
    "statusCode": 400,
    "message": "Bad Request",
    "errorKey": "bad-request",
    "data": null,
    "fields": [
        "caption"
    ],
    "timestamp": "2023-11-01T12:04:10.248Z",
    "requestId": "62...af0"
}

I tried again without the caption property (directly with the BeReal API) and it works. So the captions have probably been moved to another endpoint.

chemokita13 commented 1 year ago

I will work on it!

AaditT commented 11 months ago

@Kan-A-Pesh @chemokita13 can you explain how to successfully call the /post/upload/data endpoint?

I am calling with this body:

{
  "postData": {
    "resize": true,
    "late": true,
    "visibility": "friends",
    "retakes": 500,
    "taken_at": "2023-12-01T10:06:22.248Z",
    "location": "1,1"
  },
  "tokenData":  <JWT TOKEN from /login/verify>
}

and am getting the following response:

{
  "status": 500,
  "message": "Internal server error",
  "data": {
    "response": {
      "status": 400,
      "message": "Token not generated",
      "data": {
        "name": "JsonWebTokenError",
        "message": "jwt must be provided"
      }
    },
    "status": 400,
    "message": "Token not generated",
    "name": "HttpException"
  }
}
Kan-A-Pesh commented 11 months ago

You need to use the postDataToken generated by the /post/upload/getData endpoint

To post you first need to get three tokens (front photo, back photo and post) with /post/upload/getData endpoint by adding your JWT token generated from /login/verify in the request body\ Tokens are returned with the following format:

{
  "status": 201,
  "message": "Photo created",
  "data": {
    "firstPhotoToken": "tokentokentokentoken",
    "secondPhotoToken": "tokentokentokentoken",
    "postDataToken": "tokentokentokentoken"
  }
}

Then post your photos with the /post/upload/photo endpoint by adding the JWT corresponding to the front (firstPhotoToken) or back (secondPhotoToken) photo

After posting the two photos you can call /post/upload/getData with the third JWT token (postDataToken) and your BeReal should be posted!

AaditT commented 11 months ago

You need to use the postDataToken generated by the /post/upload/getData endpoint

To post you first need to get three tokens (front photo, back photo and post) with /post/upload/getData endpoint by adding your JWT token generated from /login/verify in the request body Tokens are returned with the following format:

{
  "status": 201,
  "message": "Photo created",
  "data": {
    "firstPhotoToken": "tokentokentokentoken",
    "secondPhotoToken": "tokentokentokentoken",
    "postDataToken": "tokentokentokentoken"
  }
}

Then post your photos with the /post/upload/photo endpoint by adding the JWT corresponding to the front (firstPhotoToken) or back (secondPhotoToken) photo

After posting the two photos you can call /post/upload/getData with the third JWT token (postDataToken) and your BeReal should be posted!

@Kan-A-Pesh Hi, before I was not posting both my front photo and back photos, but am now doing it. To recap, I am able to (1) get my three tokens from /post/upload/getData (2) post both my front and back photos using the respective jwt token with /post/upload/photo. However, on step (3) I am using the postDataToken JWT token and am still getting the following 500.

{
  "status": 500,
  "message": "Internal server error",
  "data": {
    "response": {
      "status": 400,
      "message": "Token not generated",
      "data": {
        "name": "JsonWebTokenError",
        "message": "jwt must be provided"
      }
    },
    "status": 400,
    "message": "Token not generated",
    "name": "HttpException"
  }
}

Is there a potential issue with my request:

curl -X 'POST' \
  'https://berealapi.fly.dev/post/upload/data' \
  -H 'accept: */*' \
  -H 'Content-Type: application/json' \
  -d '{
  "postData": {
    "resize": false,
    "late": true,
    "visibility": "friends",
    "retakes": 0,
    "taken_at": "2023-12-01T10:06:22.248Z",
    "location": "[1,1]"
  },
  "tokenData": "postDataToken JWT"
}'
chemokita13 commented 11 months ago

You need to use the postDataToken generated by the /post/upload/getData endpoint To post you first need to get three tokens (front photo, back photo and post) with /post/upload/getData endpoint by adding your JWT token generated from /login/verify in the request body Tokens are returned with the following format:

{
  "status": 201,
  "message": "Photo created",
  "data": {
    "firstPhotoToken": "tokentokentokentoken",
    "secondPhotoToken": "tokentokentokentoken",
    "postDataToken": "tokentokentokentoken"
  }
}

Then post your photos with the /post/upload/photo endpoint by adding the JWT corresponding to the front (firstPhotoToken) or back (secondPhotoToken) photo After posting the two photos you can call /post/upload/getData with the third JWT token (postDataToken) and your BeReal should be posted!

@Kan-A-Pesh Hi, before I was not posting both my front photo and back photos, but am now doing it. To recap, I am able to (1) get my three tokens from /post/upload/getData (2) post both my front and back photos using the respective jwt token with /post/upload/photo. However, on step (3) I am using the postDataToken JWT token and am still getting the following 500.

{
  "status": 500,
  "message": "Internal server error",
  "data": {
    "response": {
      "status": 400,
      "message": "Token not generated",
      "data": {
        "name": "JsonWebTokenError",
        "message": "jwt must be provided"
      }
    },
    "status": 400,
    "message": "Token not generated",
    "name": "HttpException"
  }
}

Is there a potential issue with my request:

curl -X 'POST' \
  'https://berealapi.fly.dev/post/upload/data' \
  -H 'accept: */*' \
  -H 'Content-Type: application/json' \
  -d '{
  "postData": {
    "resize": false,
    "late": true,
    "visibility": "friends",
    "retakes": 0,
    "taken_at": "2023-12-01T10:06:22.248Z",
    "location": "[1,1]"
  },
  "tokenData": "postDataToken JWT"
}'

Hey! @AaditT Are you sending also the login token in headers? I think isnt delcared in api docs but is necessary. I let you an example in typescript and axios

     const postDataToSend: { tokenData: string; postData: PostData } = {
                tokenData: postDataToken,
                postData: postData,
            };
            const responseOptions = await axiosInstance.post(
                "/post/upload/data",
                postDataToSend,
                {
                    headers: {
                        token: token,
                    },
                }
            );
AaditT commented 11 months ago

Hi @chemokita13 I now tried using tthe login toker in header as such:

curl -X 'POST' \
  'https://berealapi.fly.dev/post/upload/data' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'token: <JWT from /login/verify>' \
  -d '{
    "postData": {
      "resize": false,
      "late": true,
      "visibility": "friends",
      "retakes": 0,
      "taken_at": "2023-12-18T10:06:22.248Z",
      "location": "[1,1]"
    },
    "tokenData": "<JWT postDataToken from /post/upload/getData>"
  }'

but am still getting the same internal server error

chemokita13 commented 11 months ago

Hi @chemokita13 I now tried using tthe login toker in header as such:

curl -X 'POST' \
  'https://berealapi.fly.dev/post/upload/data' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'token: <JWT from /login/verify>' \
  -d '{
    "postData": {
      "resize": false,
      "late": true,
      "visibility": "friends",
      "retakes": 0,
      "taken_at": "2023-12-18T10:06:22.248Z",
      "location": "[1,1]"
    },
    "tokenData": "<JWT postDataToken from /post/upload/getData>"
  }'

but am still getting the same internal server error

Idk, it seems an error with maybe the "taken_at" param that is harder to implement, let me research it