bic-org / Boxtech

Boxtech API is a global container database containing technical and safety information, such as tare weight, size/type and max stacking capacity for containers.
https://www.bic-boxtech.org
25 stars 7 forks source link

Cannot get JSON output #47

Closed kenlane-af closed 1 week ago

kenlane-af commented 2 months ago

I am able to retrieve my auth token and submit a curl GET for a BIC Code, but the API returns some <!doctype html> data and I cannot see the JSON output described in the documentation.

I've tried with both curl and Postman and tried tweaking the "Accept" parameters. I notice an error from Cloudflare but I am sure it is something more simple than that. Here is the erbose curl output:

kenneths-mbp:~ kennylane$ curl -v --location 'https://api.bic-boxtech.org/api/v2.0/codes/MNBU' --header 'Authorization: '

  • Trying 104.26.6.83:443...
  • Connected to api.bic-boxtech.org (104.26.6.83) port 443
  • ALPN: curl offers h2,http/1.1
  • (304) (OUT), TLS handshake, Client hello (1):
  • CAfile: /etc/ssl/cert.pem
  • CApath: none
  • (304) (IN), TLS handshake, Server hello (2):
  • (304) (IN), TLS handshake, Unknown (8):
  • (304) (IN), TLS handshake, Certificate (11):
  • (304) (IN), TLS handshake, CERT verify (15):
  • (304) (IN), TLS handshake, Finished (20):
  • (304) (OUT), TLS handshake, Finished (20):
  • SSL connection using TLSv1.3 / AEAD-AES256-GCM-SHA384
  • ALPN: server accepted h2
  • Server certificate:
  • subject: CN=bic-boxtech.org
  • start date: Mar 10 21:02:47 2024 GMT
  • expire date: Jun 8 21:02:46 2024 GMT
  • subjectAltName: host "api.bic-boxtech.org" matched cert's "*.bic-boxtech.org"
  • issuer: C=US; O=Google Trust Services LLC; CN=GTS CA 1P5
  • SSL certificate verify ok.
  • using HTTP/2
  • [HTTP/2] [1] OPENED stream for https://api.bic-boxtech.org/api/v2.0/codes/MNBU
  • [HTTP/2] [1] [:method: GET]
  • [HTTP/2] [1] [:scheme: https]
  • [HTTP/2] [1] [:authority: api.bic-boxtech.org]
  • [HTTP/2] [1] [:path: /api/v2.0/codes/MNBU]
  • [HTTP/2] [1] [user-agent: curl/8.4.0]
  • [HTTP/2] [1] [accept: /]
  • [HTTP/2] [1] [authorization:

    GET /api/v2.0/codes/MNBU HTTP/2 Host: api.bic-boxtech.org User-Agent: curl/8.4.0 Accept: / Authorization:

    < HTTP/2 200 < date: Tue, 30 Apr 2024 15:21:46 GMT < content-type: text/html < last-modified: Thu, 25 Apr 2024 13:56:50 GMT < x-amz-server-side-encryption: AES256 < vary: Accept-Encoding < x-cache: Error from cloudfront < via: 1.1 d1dad7d3c339d87d553c26a84c9ca5d2.cloudfront.net (CloudFront) < x-amz-cf-pop: IAD55-P4 < x-amz-cf-id: VQDfwgAOj4ffjTQlqWrTnQRZ5nlZcHvqjo5VWnJ15nI9zGi7SPHFyg== < age: 229 < cf-cache-status: DYNAMIC < report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s="}],"group":"cf-nel","max_age":604800} < nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800} < server: cloudflare < cf-ray: 87c885fdcf8482e1-IAD < <!doctype html>

    BIC Boxtech | Global Container Database

  • Connection #0 to host api.bic-boxtech.org left intact
cmsdroff commented 1 month ago

Hi @kenlane-af

Thanks for raising, I think this should help:

  1. Authenticate using endpoint
curl --location --request POST 'https://app.bic-boxtech.org/api/v2.0/oauth/token' \
--header 'Accept: application/json' \
--header 'Authorization: Basic ZGF2aWRAY...'

if your using postman then in the 'Auth' tab set the auth type to Basic Auth and enter your Boxtech Username and Password in the boxes provided, otherwise you will need to base64 encode separating the username and password with a :, the output will look like above, just make sure the full authorisation is provided in place of ZGF2aWRAY...

  1. Call the BIC Code Endpoint
curl --location 'https://app.bic-boxtech.org/api/v2.0/codes/MNBU' \
--header 'Accept: application/json' \
--header 'Authorization: eyJraWQiOiJUVW9vRTd...'

make sure you put the full token returned from the auth endpoint in the above code to replace eyJraWQiOiJUVW9vRTd...

you will get a response as below

[
    {
        "code": "MNBU",
        "name": "MAERSK A/S",
        "address": {
            "country": "Denmark"
        }
    }
]
ceciliamarquesb commented 3 weeks ago

I have the same problem. I can get the token from authenticate endpoint, apply it on the authorization header on BIC Code endpoint and the result is a <!doctype html>

BIC

This happens even if I do in the website

BIC2

tvanhove commented 3 weeks ago

We are having the same issue as @ceciliamarquesb

cmsdroff commented 3 weeks ago

The swagger and API are returning successfully, so we will look into your accounts to see if some permissions have not been set,

Could you please login to https://portal.bic-code.org using your credentials and ensure you have accepted the terms and conditions for the BoTech api please? the T&C's button should be green not red like below.

Screenshot 2024-06-07 at 08 46 07

Here's the swagger response showing results.

Screenshot 2024-06-07 at 08 43 19

@declanoconnor can you check over this also please?

tvanhove commented 3 weeks ago

@cmsdroff well that did it! Thank you for the quick reply!

Would it be possible to give some response on the API that gives an indication if the T&C have not been accepted?

declanoconnor commented 3 weeks ago

@cmsdroff well that did it! Thank you for the quick reply!

Would it be possible to give some response on the API that gives an indication if the T&C have not been accepted?

Thanks for the feedback @tvanhove

The API should now return an appropriate response & other permission errors should now be clearer.

ceciliamarquesb commented 3 weeks ago

The swagger and API are returning successfully, so we will look into your accounts to see if some permissions have not been set,

Could you please login to https://portal.bic-code.org using your credentials and ensure you have accepted the terms and conditions for the BoTech api please? the T&C's button should be green not red like below.

Screenshot 2024-06-07 at 08 46 07

Here's the swagger response showing results.

Screenshot 2024-06-07 at 08 43 19

@declanoconnor can you check over this also please?

Thank you @cmsdroff

Issue solved!