[{"data":1,"prerenderedAt":209},["Reactive",2],{"/guides/node/superagent/using-cookies":3,"related:gX2Kya3W94":127},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"language":10,"library":11,"property":12,"output":13,"related":14,"default":6,"body":17,"_type":122,"_id":123,"_source":124,"_file":125,"_extension":126},"/guides/node/superagent/using-cookies","superagent",false,"","Using cookies to convert HTML documents to PDF","Learn how to add custom Cookies when requesting an URL to be converted in PDF with PDFShift's API. It allows you to pursue an active session for instance, that will authenticate the request as a specific user before converting the page to PDF. This guide explains you how using Node and the SuperAgent library.","Node","SuperAgent","cookies","pdf",[15,16],"send-custom-http-headers","accessing-secured-pages",{"type":18,"children":19,"toc":119},"root",[20,28,41,53,65,114],{"type":21,"tag":22,"props":23,"children":24},"element","p",{},[25],{"type":26,"value":27},"text","In this comprehensive guide, we will demonstrate the step-by-step process of incorporating custom Cookies into your URL request for PDF conversion using PDFShift's API. By leveraging this functionality, you can maintain an active session, enabling authentication as a specific user before generating the PDF document.",{"type":21,"tag":22,"props":29,"children":30},{},[31,33,39],{"type":26,"value":32},"To do so, we'll use the ",{"type":21,"tag":34,"props":35,"children":37},"code",{"className":36},[],[38],{"type":26,"value":12},{"type":26,"value":40}," parameter when sending a request to PDFShift. It expects a list of dictionnary that contains the name and the value of the cookies (more details after):",{"type":21,"tag":42,"props":43,"children":48},"pre",{"className":44,"code":46,"language":47,"meta":7},[45],"language-javascript","const superagent = require('superagent');\nconst fs = require('fs');\n\n// You can get an API key at https://pdfshift.io\napi_key = 'sk_xxxxxxxxxxxx'\n\nparams = {\n    source: 'https://www.example.com',\n    // The \"cookies\" parameter expects a list of dictionnary that contains the name and the value of the cookies\n    cookies: [\n        { name: 'PHPSESSID', value: 'el4ukv0kqbvoirg7nkp4dncpk3' }\n    ]\n}\n\nlet response = await superagent\n    .post('https://api.pdfshift.io/v3/convert/pdf')\n    .set('X-API-Key', api_key)\n    .send(params);\n\nfs.writeFileSync('result.pdf', response.body);\n\nconsole.log('The PDF document was generated and saved to result.pdf');\n","javascript",[49],{"type":21,"tag":34,"props":50,"children":51},{"__ignoreMap":7},[52],{"type":26,"value":46},{"type":21,"tag":22,"props":54,"children":55},{},[56,58,63],{"type":26,"value":57},"The ",{"type":21,"tag":34,"props":59,"children":61},{"className":60},[],[62],{"type":26,"value":12},{"type":26,"value":64}," parameter accept the following parameters:",{"type":21,"tag":66,"props":67,"children":68},"ul",{},[69,81,92,103],{"type":21,"tag":70,"props":71,"children":72},"li",{},[73,79],{"type":21,"tag":34,"props":74,"children":76},{"className":75},[],[77],{"type":26,"value":78},"name",{"type":26,"value":80}," : The name of the cookie.",{"type":21,"tag":70,"props":82,"children":83},{},[84,90],{"type":21,"tag":34,"props":85,"children":87},{"className":86},[],[88],{"type":26,"value":89},"value",{"type":26,"value":91},": The value of the cookie.",{"type":21,"tag":70,"props":93,"children":94},{},[95,101],{"type":21,"tag":34,"props":96,"children":98},{"className":97},[],[99],{"type":26,"value":100},"secure",{"type":26,"value":102},": A boolean (defaults to false) that will tell the browser to only send the cookie if the request is being sent over HTTPS.",{"type":21,"tag":70,"props":104,"children":105},{},[106,112],{"type":21,"tag":34,"props":107,"children":109},{"className":108},[],[110],{"type":26,"value":111},"http_only",{"type":26,"value":113},": A boolean (defaults to false) that will tell the browser to not expose it to client-side scripts.",{"type":21,"tag":22,"props":115,"children":116},{},[117],{"type":26,"value":118},"Like in our guide to send custom HTTP headers or to access secured pages, this allows you to protect your documents from any visitors while allowing PDFShift to access the page and convert it to PDF.",{"title":7,"searchDepth":120,"depth":120,"links":121},2,[],"markdown","content:guides:node:superagent:using-cookies.md","content","guides/node/superagent/using-cookies.md","md",[128,132,136,140,144,148,152,156,160,164,168,172,176,180,184,188,192,196,200,204,205],{"_path":129,"title":130,"language":10,"library":11,"_id":131},"/guides/node/superagent/accessing-secured-pages","Accessing secured pages","content:guides:node:superagent:accessing-secured-pages.md",{"_path":133,"title":134,"language":10,"library":11,"_id":135},"/guides/node/superagent/adding-a-custom-header-or-footer","Adding a custom header or footer","content:guides:node:superagent:adding-a-custom-header-or-footer.md",{"_path":137,"title":138,"language":10,"library":11,"_id":139},"/guides/node/superagent/adding-a-text-watermark","Adding a text watermark","content:guides:node:superagent:adding-a-text-watermark.md",{"_path":141,"title":142,"language":10,"library":11,"_id":143},"/guides/node/superagent/adding-an-image-watermark","Adding an image watermark","content:guides:node:superagent:adding-an-image-watermark.md",{"_path":145,"title":146,"language":10,"library":11,"_id":147},"/guides/node/superagent/avoid-conversion-on-error","Avoid the conversion on error when loading the document","content:guides:node:superagent:avoid-conversion-on-error.md",{"_path":149,"title":150,"language":10,"library":11,"_id":151},"/guides/node/superagent/convert-html-to-pdf-from-a-url","Convert an HTML document to PDF from a URL","content:guides:node:superagent:convert-html-to-pdf-from-a-url.md",{"_path":153,"title":154,"language":10,"library":11,"_id":155},"/guides/node/superagent/convert-html-to-pdf-from-raw-html","Convert an HTML document to PDF from raw HTML","content:guides:node:superagent:convert-html-to-pdf-from-raw-html.md",{"_path":157,"title":158,"language":10,"library":11,"_id":159},"/guides/node/superagent/define-a-time-limit","Define a time limit","content:guides:node:superagent:define-a-time-limit.md",{"_path":161,"title":162,"language":10,"library":11,"_id":163},"/guides/node/superagent/exporting-only-a-specific-set-of-pages","Exporting only a specific set of pages","content:guides:node:superagent:exporting-only-a-specific-set-of-pages.md",{"_path":165,"title":166,"language":10,"library":11,"_id":167},"/guides/node/superagent/generate-a-document-with-full-height","Generate a document with full height","content:guides:node:superagent:generate-a-document-with-full-height.md",{"_path":169,"title":170,"language":10,"library":11,"_id":171},"/guides/node/superagent/loading-css-from-a-string","Loading CSS from a string","content:guides:node:superagent:loading-css-from-a-string.md",{"_path":173,"title":174,"language":10,"library":11,"_id":175},"/guides/node/superagent/loading-css-from-a-url","Loading CSS from a URL","content:guides:node:superagent:loading-css-from-a-url.md",{"_path":177,"title":178,"language":10,"library":11,"_id":179},"/guides/node/superagent/loading-javascript-from-a-string","Loading Javascript from a string","content:guides:node:superagent:loading-javascript-from-a-string.md",{"_path":181,"title":182,"language":10,"library":11,"_id":183},"/guides/node/superagent/loading-javascript-from-a-url","Loading Javascript from a URL","content:guides:node:superagent:loading-javascript-from-a-url.md",{"_path":185,"title":186,"language":10,"library":11,"_id":187},"/guides/node/superagent/protecting-the-generated-pdf","Protecting the generated PDF","content:guides:node:superagent:protecting-the-generated-pdf.md",{"_path":189,"title":190,"language":10,"library":11,"_id":191},"/guides/node/superagent/receive-a-webhook-event","Receive a webhook event","content:guides:node:superagent:receive-a-webhook-event.md",{"_path":193,"title":194,"language":10,"library":11,"_id":195},"/guides/node/superagent/save-your-pdf-online-and-get-back-a-url","Save your PDF online and get back a URL","content:guides:node:superagent:save-your-pdf-online-and-get-back-a-url.md",{"_path":197,"title":198,"language":10,"library":11,"_id":199},"/guides/node/superagent/save-your-pdf-to-your-amazon-s3-bucket","Save your PDF to your Amazon S3 Bucket","content:guides:node:superagent:save-your-pdf-to-your-amazon-s3-bucket.md",{"_path":201,"title":202,"language":10,"library":11,"_id":203},"/guides/node/superagent/send-custom-http-headers","Send custom HTTP headers","content:guides:node:superagent:send-custom-http-headers.md",{"_path":4,"title":8,"language":10,"library":11,"_id":123},{"_path":206,"title":207,"language":10,"library":11,"_id":208},"/guides/node/superagent/waiting-for-a-custom-element-to-be-ready","Waiting for a custom element to be ready","content:guides:node:superagent:waiting-for-a-custom-element-to-be-ready.md",1785426831996]