POST 405 Method Not Allowed error in API

Hi,

I am testing an API to convert html page to a PDF. I have set up an API Action according to documentation available from the API developer and it’s authorising the API call correctly. However, I am getting this error when calling/loading the API Action with url of the page I want to convert.

POST 405 Method Not Allowed

This is the error I am getting when I look under Network Tab in the DevTools:

405 - HTTP verb used to access this page is not allowed. The page you are looking for cannot be displayed because an invalid method (HTTP verb) was used to attempt access.

The code for API Action is (some details have been changed):

<dmx-api-action
 id="api1" noload="true" method="post"
 url="https://api.pdfcrowd.com/convert/"
 dmx-header:authorization="'xxxxx:xxxxxxxxxx'"
 dmx-header:content-type="'application/x-www-form-urlencoded'"
 dmx-bind:url="'https://xxx.xxxxxx.com.au/xxxx.html'
 dmx-param:product_id="'{{products_techsheets_connect.data.products_techsheet_query[0].SourceVarietyGSUID}}'"
 dmx-header:accept="'*/*'">
</dmx-api-action>

I’m not sure whether the API action I have setup is incorrect or there’s a setting I need to change on the IIS Web server.

Any help in resolving the issue is greatly appreciated. Thank you.

I think that the authorization header is incorrect, the method used for that api is HTTP Basic Access Authentication.

Header should look like Basic QWxhZGRpbjpPcGVuU2VzYW1l, the username:password are base64 encoded.

Alternative you can try to put it in front of the url like https://username:password@api.pdfcrowd.com/convert/.

Hi @patrick, thanks for sending information on this issue.

I tried both methods - Base64 encoded authorisation and prepending the url with username:password; I am still getting the POST 405 (Method Not Allowed) error.

It doesn’t seem to be an issue with the authorisation step, the error is happening when a POST call is made to the PDF conversion API along with the url to convert.

Edit: It looks like the error is coming from the IIS web server where the website (url for conversion) is hosted. This is coming up in the dev tools:

1. Request Method: POST 2. Status Code: 405 Method Not Allowed 3. Remote Address: xxx.xx.xxx.xxx:443 4. Referrer Policy: no-referrer-when-downgrade

Ah, I see it, you are setting a dynamic url that replaces the api url. You need to send that url as input data, not setting it as a dynamic attribute.

dmx-bind:url="'https://xxx.xxxxxx.com.au/xxxx.html'"

should become

dmx-data:url="'https://xxx.xxxxxx.com.au/xxxx.html'"

After changing the code, I have started getting the CORS error.

I think the reason I’m getting the CORS error is because the url I’m sending to API for PDF conversion contains dynamically generated 'product_id=xxx.xxx` as query parameter, hence making it different from the main domain url.

I have added access-control-allow-origin: * but it’s not fixing the CORS issue.

Do you own the api server? The access-control-allow-origin needs to be set on the api server and is not something that you can setup on the client.

No, I am using a third party api. I will contact the api developer to provide me information on resolving the CORS issue.

Many thanks for your support and help in this matter @patrick :slight_smile:

Hi @patrick,

I have resolved issues with the authorisation and CORS for the api call. However, after various attempts to get it working, it seems the API Action call is not picking up any Data that has been entered under the INPUT DATA API Action Properties.

As I am converting a web page to PDF, I’m adding URL of the source web page under INPUT DATA properties. But when I call the API, this URL is not being added to the api URL, resulting in an invalid POST api call.

In the code below, the API Call is not loading the dmx-data:url="" Input Data correctly.

<dmx-api-action id="api1" noload="true" url="https://api.pdfcrowd.com/convert/" method="post"
 dmx-data:url="'https://xyz.xyz.com.au/index.html'"
 dmx-param:use_print_media="1"
 dmx-header:authorization="'BASIC&nbsp;gddhy7846r834yfyeejkfreyfr'"
 dmx-header:content-type="'multipart/form-data; charset=utf-8; boundary=&amp;quot;user defined&amp;quot;'">
</dmx-api-action>

This is the final Request URL when I’m calling the API Action. It’s adding the Parameter but it’s missing URL of the source web page (Input Data).

Request URL: https://api.pdfcrowd.com/convert/?use_print_media=1

Could you please look into this issue and help me in resolving this? Thank you.

The url parameter is not in the request url, it should be in the post data. You can see it with chrome devtools.

According to the API provider’s guidelines, a complete Request URL should look like this when making a POST call:

Request URL: https://api.pdfcrowd.com/convert/?url=https://xyz.xyz.com.au/index.html&use_print_media=1

But Input Data API Action Property (url=https://xyz.xyz.com.au/index.html) is not correctly being appended to the Request URL when making the POST call.

I have checked the Network Tab in Dev Tools and Request URL is not including the source URL for conversion.

Have I entered the source URL for PDF conversion in a wrong field?

If it needs to be added to the url then add it to the query parameters instead of the input data

The parameter has been correctly appended to the api URL.

There’s still an issue, which I will need to check with the api developer.

Thanks for your help @patrick :slight_smile: