Decoding
The responses returned by the Async API for binary requests require you to decode the data as they are encoded using Base64 encoding. This allows the binary data to be sent as a text string, which can then be decoded back into its original form when you want to use it.
Example Request:
curl --request POST \
--url "https://async.scraperapi.com/jobs" \
--header "Content-Type: application/json" \
--data '{
"apiKey": "API_KEY",
"url": "https://pdfobject.com/pdf/sample.pdf"
}'import requests
r = requests.post(
url='https://async.scraperapi.com/jobs',
json={
"apiKey": "API_KEY",
"url": "https://pdfobject.com/pdf/sample.pdf"
}
)
print(r.text)import axios from 'axios';
(async () => {
const { data } = await axios.post(
'https://async.scraperapi.com/jobs',
{
apiKey: 'API_KEY',
url: 'https://pdfobject.com/pdf/sample.pdf'
},
{
headers: { 'Content-Type': 'application/json' }
}
);
console.log(data);
})();Decode the response - Use the job ID from your response in place of <JOB_ID> to decode that specific result:
curl https://async.scraperapi.com/jobs/<JOB_ID> \
| jq -r '.response.base64EncodedBody' \
| base64 -d > name.pdfimport requests
import base64
r = requests.get('https://async.scraperapi.com/jobs/<JOB_ID>')
base64_encoded_body = r.json()['response']['base64EncodedBody']
pdf_data = base64.b64decode(base64_encoded_body)
with open('name.pdf', 'wb') as f:
f.write(pdf_data)import axios from 'axios';
import fs from 'fs';
(async () => {
const response = await axios.get('https://async.scraperapi.com/jobs/<JOB_ID>');
const base64EncodedBody = response.data.response.base64EncodedBody;
const pdfData = Buffer.from(base64EncodedBody, 'base64');
fs.writeFileSync('name.pdf', pdfData);
})();Last updated

