How to Write a Code to Push a Post and its Associated Comments to a Target Wordpress Site Using the Wordpress REST API?

So it depends which one you want/need to use.

It’s one or the other:
Basic with username + password
• or Bearer with JWT

Well, I just set up the bearer token, so let’s use that.

Warning: JWT tokens are usually set to expire after a while.

There’s a highly secure (PCI) API we’re using, and for that they expire after 2 minutes (and they are single-use, too).

I imagine the Wordpress tokens are less stringent. :sweat_smile:

I’m using:

These seem to last forever. I generated the code and added to the config file.

About to test it once I get this script written.

Write me a scipt which will post to Wordpress using the WORDPRESS REST API using the POST method. We are using a bearer token.

Sure, here’s a Pipedream component that sends a POST request to your WordPress REST API endpoint using a Bearer token for authentication. You’ll need to replace your-endpoint with the specific endpoint you want to test. import { axios } from "@pipedream/platform"; export default defineComponent({ props: { targetSiteURL: { type: "string", label: "Target Site URL", description: "The URL of your WordPress REST API endpoint", }, jwtToken: { type: "string", label: "JWT Token", description: "The JWT token for your WordPress site", }, }, async run({ $ }) { const response = await axios($, { method: "POST", url: `${this.targetSiteURL}/your-endpoint`, headers: { Authorization: `Bearer ${this.jwtToken}`, }, // Add your data here data: { key: "value", }, }); return { url: this.targetSiteURL, response: response, }; }, }); This code will send a POST request to your specified endpoint and return the response. If you need to send specific data in the request body, you’ll need to replace key: "value" in the data property with your actual data.

You didn’t want to use this Pipedream component?

It supports the authentication already, instead of using props.

isn’t that for people using the ORG version of WP? Let me check.

It’s the self-hosted version.

The hosted version is this one.

I’m using the Wordpress.ORG Integration and I am recieving the following error:

Error
[object Object]

I filled out the Wordpress Account, Title and Post.

I’m sorry to hear that you’re encountering an error with the WordPress.org integration. The error message [object Object] is quite generic and doesn’t provide specific details about what might be going wrong. To help you better, could you please provide more details about the error? If there’s any additional information in the error message or if you could describe the steps leading up to the error, it would be very helpful. Alternatively, you can also reach out to Pipedream’s support team at https://pipedream.com/support for more comprehensive assistance.

It appears to be a syntax error.

[SyntaxError: Invalid regular expression: /^([^\/:<>\**\?"\|]+(?:\/[^\/:<>\**\?"\|]+)?$/: Unterminated group]

How should I filter it before I send it?

The error message indicates that there’s an issue with a regular expression (regex) in your code. The error message Unterminated group usually means that a parenthesis ( or ) in your regex is not closed properly. The regex you provided: /^([^\/:<>\**\?"\|]+(?:\/[^\/:<>\**\?"\|]+)?$)/ seems to have balanced parentheses, so the issue might be elsewhere in your code. Without seeing the full context of your code, it’s difficult to provide a specific solution. However, here are a few general suggestions: 1. Double-check your regex to make sure all parentheses, brackets, and braces are properly balanced. 2. Make sure you’re not accidentally escaping a parenthesis by using a backslash \ before it. 3. If you’re constructing the regex from strings, ensure that the final string is a valid regex. If you’re still having trouble, could you provide more context or perhaps share the part of the code where this regex is being used? That would help me assist you better.

I figured out that it’s the contents of the code that I’m putting in.

The contents of the code that I am putting in has HTML and COMMENTS.

It seems like the HTML and comments in your code might be causing issues. If you’re trying to post HTML content to WordPress, make sure that it’s properly escaped so it doesn’t interfere with the JSON structure of the API request. For comments, if they’re JavaScript comments in your Pipedream script, they shouldn’t cause any issues. However, if you’re trying to include comments within the HTML or JSON payload, make sure they’re properly formatted for their respective languages. If you’re still having trouble, could you please provide a snippet of the code you’re trying to post? That would help me assist you better.

here is a snippet of the code that I am trying to post.

<!-- wp:paragraph -->
<p><a href="https://www.sohh.com/tag/kodak-black/"><strong>Kodak Black</strong></a> is back in the spotlight. The Florida rapper's lawyer is now seeking to dismiss his drug case involving charges of controlled substance possession and oxycodone trafficking. Kodak's attorney contends that the seized pills were, in fact, <strong>Tylenol</strong>, not the illicit substances initially believed.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>How It All Started</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Kodak Black, the controversial rapper known for his hit song "Tunnel Vision," is making headlines again, this time for his lawyer's attempt to dismiss his drug case.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In July 2022, Kodak Black was arrested in Ft. Lauderdale and charged with possession of a controlled substance and trafficking oxycodone. However, his attorney, Bradford Cohen, argues that the pills seized by law enforcement were just <strong>Tylenol</strong>, not the illegal drugs they were thought to be.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Cohen, in his motion to dismiss obtained by <strong>TMZ</strong>, highlights that testing of a sample of the pills revealed their true nature.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>The Blame Game</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Moreover, Cohen is pointing fingers at <strong>FBI</strong> Special Agent James Mitchell, claiming bias against the South Florida native and accusing him of being involved in a massive cover-up orchestrated by the <strong>Broward Sheriff's Office</strong>.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Cohen asserts that the prosecution attempted to withhold a body cam video showing an officer surveilling Kodak. In the video, the officer can be heard saying he's "always ready," and the camera focused on his firearm, creating a potentially intimidating atmosphere.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Just Tylenol?</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Adding to the controversy, Cohen asserts that the pills that were tested and proved to be <strong>Tylenol</strong> were destroyed during the process, and officials failed to provide any written report on the results.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This, according to the attorney, raises suspicions about the legitimacy of the case against Kodak Black. Cohen goes on to claim that the entire arrest and subsequent charges were part of a "coordinated takedown" of the rapper. With these allegations in mind, Kodak Black's attorney is seeking to have the drug case entirely dismissed.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Cohen contends that the rapper's arrest was a waste of taxpayer money and highlights the lack of evidence and transparency surrounding the investigation.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p><em>Updated By: Kynedei Iman Hobbs (11/14/23 at 4:12 pm)</em></p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Kodak Black Booked At Florida Jail & Released On New $250K Bond</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><strong>Kodak Black</strong> had a brief encounter with the Broward County Jail in Florida. After being taken into custody for about an hour, Kodak posted a new bond of $250,000, allowing his release. The rapper's legal proceedings, led by his lawyer Bradford Cohen, were at the center of his pretrial release. This pit stop at the jail resulted from a warrant issued for his arrest due to his failure to appear at a court-mandated drug screening, a requirement stemming from a previous arrest in 2022.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Kodak Black had been on pretrial release for a prescription drug case. This release came with certain obligations, including regular check-ins with authorities and mandatory urine tests. However, Kodak failed to fulfill these requirements, leading to a court appearance.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The South Florida rapper's attorney, Bradford Cohen, argued for eliminating strict pretrial supervision in court. The judge granted the request but, as a result, increased Kodak's bond from $75,000 to $250,000.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Although this meant the "Identity Theft" rapper had to go through the booking process again and take a new mugshot, it allowed him to be released from custody.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>For Kodak's legal team, this outcome is seen as a victory. With the elimination of pretrial service check-ins, Kodak will now be free to travel and tour without restrictions.&nbsp;<br>This development is particularly significant as the rapper recently performed at the <strong>Kodak Black & Friends</strong> event on June 26, sharing the stage with other notable artists such as <strong>G Herbo </strong>and <strong>iCandy</strong>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Updated on June 27th, 2023 by Dorian Waller</p>
<!-- /wp:paragraph -->

<!-- wp:separator -->
<hr class="wp-block-separator"/>
<!-- /wp:separator -->

<!-- wp:heading -->
<h2>Arrest Warrant Issued For Kodak Black Following Absence At Drug Test Meeting</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><strong>Kodak Black</strong>, also known as Bill Kapri, is facing further legal trouble as an arrest warrant has been issued due to his failure to attend a drug testing meeting. The warrant comes as a violation of the conditions of his pretrial release in a felony drug case in Broward County.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Kodak Black is facing an arrest warrant after allegedly missing a meeting with pretrial services in a felony drug case in Broward County. The warrant was issued on June 14, following the Pompano Beach rapper's absence at a scheduled drug test on June 9.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>This violation of his pretrial release conditions has led to further legal consequences for the rapper.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Legal Troubles & Previous Arrest</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Kodak Black's legal troubles extend beyond this recent arrest warrant. In July 2022, he was initially arrested <a href="https://www.sohh.com/kodak-black-released-jail-arrested-on-drug-charges/">on multiple charges</a>, including trafficking in oxycodone, possession of a controlled substance without a prescription, and driving with an expired driver's license and tags.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The rapper posted a $75,000 bond the day after his arrest. Furthermore, in February 2022, he failed a required drug test by testing positive for Fentanyl, resulting in further complications in his legal proceedings.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The Pompano Beach rapper is scheduled to appear in court on June 26 to address the allegations against him regarding the missed drug testing. However, his team has not made any official statements regarding the situation.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Growing List Of Rappers Facing Legal Issues</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Kodak Black joins a growing list of rappers who have encountered severe legal problems recently. Artists like <a href="https://www.sohh.com/quando-ronda-arrested/"><strong>Quando Rondo</strong></a>, <a href="https://www.sohh.com/blueface-arrested/"><strong>Blueface</strong></a>, and <a href="https://www.sohh.com/playboi-carti-arrested-for-allegedly-assaulting-pregnant-girlfriend/"><strong>Playboi Carti</strong></a> have faced their fair share of legal challenges and found themselves in the spotlight for the wrong reasons.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Kodak Black Released From Jail After Being Arrested On Drug Charges</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Florida rapper <strong>Kodak Black</strong> was released from jail on a $75k bond on Saturday, July 16. He was arrested the day before on drug trafficking charges.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Free From Jail</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Last Saturday (July, 16), after being charged with the possession of oxycodone pills, Kodak Black, real name Bill Kahan Kapri, was released from jail on a $75k bond.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Around 5 pm on Saturday, a <a href="https://twitter.com/RyanNelsonTV/status/1548457633228607490" target="_blank" rel="noreferrer noopener">reporter from NBC6</a> posted a video on Twitter showing the rapper had left the Broward County Jail in South Florida.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>"Never Judge a case based on an arrest. There are always additional facts and circumstances that give rise to a defense, especially in this case," said Bradford Cohen, Kodak's defense attorney, in a <a href="https://twitter.com/bradfordcohen/status/1548309562083512321?cxt=HHwWgsCgpf3V2fwqAAAA" target="_blank" rel="noreferrer noopener">tweet</a> Saturday morning. Cohen also stated that they would move forward to resolve Kodak's issue quickly.</p>
<!-- /wp:paragraph -->

<!-- wp:embed {"url":"https://twitter.com/bradfordcohen/status/1548309562083512321?cxt=HHwWgsCgpf3V2fwqAAAA","type":"rich","providerNameSlug":"twitter","responsive":true} -->
<figure class="wp-block-embed is-type-rich is-provider-twitter wp-block-embed-twitter"><div class="wp-block-embed__wrapper">
https://twitter.com/bradfordcohen/status/1548309562083512321?cxt=HHwWgsCgpf3V2fwqAAAA
</div></figure>
<!-- /wp:embed -->

<!-- wp:heading -->
<h2>Alleged Possession Of Oxycodone Pills</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>According to a tweet from <a href="https://twitter.com/andyslater/status/1548119959590473730?s=21&t=d6LRVBSrKtT8I6_-iF9Ldw" target="_blank" rel="noreferrer noopener">Andy Slater</a>, a radio talk show host based in Florida, this 25-year-old rapper was arrested on Friday because of trafficking.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:quote -->
<blockquote class="wp-block-quote"><p>"Cops pulled over the rapper and during a search found 30+ Oxycodone pills and over $50,000 in cash during a search."</p></blockquote>
<!-- /wp:quote -->

<!-- wp:paragraph -->
<p>It was <a href="https://www.cnn.com/2022/07/16/entertainment/rapper-kodak-black-arrested-florida/index.html" target="_blank" rel="noreferrer noopener">reported</a> that while the rapper was driving a purple Dodge Durango on the Florida Highway, the patrol noticed that the tints of Kodak's car windows seemed darker than the legal limit.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Also, it was discovered that the rapper's license had expired, and so did the vehicle's registration.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>When the police searched the car, they found nearly $75,000 in cash and a small clear bag containing 31 white oxycodone tablets. According to the <a href="https://www.cdc.gov/opioids/basics/prescribed.html" target="_blank" rel="noreferrer noopener">CDC</a>, oxycodone is an opioid drug that treats pain and can be highly addictive. Overdosing on prescription opioids can stop breathing and lead to death.</p>
<!-- /wp:paragraph -->