Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

POST call in hook should set the content-type to application/json;version=2 #73

Open
sunank200 opened this issue Apr 7, 2023 · 0 comments · May be fixed by #74
Open

POST call in hook should set the content-type to application/json;version=2 #73

sunank200 opened this issue Apr 7, 2023 · 0 comments · May be fixed by #74

Comments

@sunank200
Copy link

sunank200 commented Apr 7, 2023

Currently, the POST request does not work properly in _do_api_call as the Content-Type HTTP header should be set for PUT and POST requests.

Here by default the content type is not set for POST which results in the 415 error like the following:

requests.exceptions.HTTPError: 415 Client Error: Unsupported Media Type for url: https://api.fivetran.com/v1/groups/

This is done as part of PATCH calls as https://github.com/fivetran/airflow-provider-fivetran/blob/main/fivetran_provider/hooks/fivetran.py#L117
Similar change is required for POST calls

References:
According to the RFC 7231 section 3.1.5.5:

A sender that generates a message containing a payload body SHOULD generate a Content-Type header field in that message unless the intended media type of the enclosed representation is unknown to the sender. If a Content-Type header field is not present, the recipient MAY either assume a media type of "application/octet-stream" ([RFC2046], Section 4.5.1) or examine the data to determine its type.

It means that the Content-Type HTTP header should be set for PUT and POST requests.

Change required:
Add the following line after: https://github.com/fivetran/airflow-provider-fivetran/blob/main/fivetran_provider/hooks/fivetran.py#L114

 headers.update({"Content-Type": "application/json;version=2"})
@sunank200 sunank200 linked a pull request Apr 7, 2023 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant