Cant inject javascript into Post API (solved)

hello
i cant inject javascript into body, header or footer using post API html.
how to do that?
wrap in <div> stil not working
not wraping with anything it was parsed as <p>

There are two ways you could approach it:

  1. Using post HTML
    You’ll be able to add a script tag to the body HTML using the API, but you’ll want to ensure that you’re wrapping your HTML like this:
<!--kg-card-begin: html-->
<p>HTML goes here</p>
<!--kg-card-end: html-->
  1. Use Code Injection via the API
    Alternatively, you can write a script tag to codeinjection_foot or codeinjection_head via the API call for the post.
1 Like

thank you very much for the reply.

<div><script>console.log('hello')</script></div>
failed

<pre><script>console.log('hello')</script></pre>
failed

will try using
<!--kg-card-begin: html-->

method 2, failed.
post the script like

"codeinjection_foot": <script>console.log('hello')</script>,


cant find it when checking the post thru admin page.

or is it because of cloudflare. but i already bypass WAF for admin api

I tested the API call with this property for Code Injection:

codeinjection_foot: `<script>console.log('Hello from the foot')</script>`

And like this in the post body:

html: "<!--kg-card-begin: html--><p>Some post content</p><script>console.log('Hello from the foot')</script><!--kg-card-end: html-->",

I can confirm that both methods worked. It could be something happening with Cloudflare or something in how you’re coding your API calls. We’ll need some more info to help!

2 Likes

i can confirm both method works perfectly.
thank you very much RyanF :pray:

1 Like