<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: SIC</title>
    <description>The latest articles on DEV Community by SIC (@sjewkdsa).</description>
    <link>https://dev.to/sjewkdsa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1441042%2F619fb815-796f-4ead-bee3-86ba4dd25231.png</url>
      <title>DEV Community: SIC</title>
      <link>https://dev.to/sjewkdsa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sjewkdsa"/>
    <language>en</language>
    <item>
      <title>401 Error in Wordpress Plugin</title>
      <dc:creator>SIC</dc:creator>
      <pubDate>Mon, 22 Apr 2024 06:49:23 +0000</pubDate>
      <link>https://dev.to/sjewkdsa/solidity-problem-4mme</link>
      <guid>https://dev.to/sjewkdsa/solidity-problem-4mme</guid>
      <description>&lt;p&gt;When I attempt to call REST api in wordpress plugin.&lt;br&gt;
For example mysite.com/wp-json/pap/v1/pixels, then I get 401 error.&lt;br&gt;
So I add define( 'WP_ENVIRONMENT_TYPE', 'local' ); in wp_config.php.&lt;br&gt;
then add application key value and copy the api key.&lt;br&gt;
then add header as 'Authentication', 'Bearer '.&lt;br&gt;
But I still get error.&lt;/p&gt;

&lt;p&gt;import React, { useState, useEffect } from 'react';&lt;br&gt;
import { render } from '@wordpress/element';&lt;/p&gt;

&lt;p&gt;// Define the colors array&lt;br&gt;
const colors = [&lt;br&gt;
    '#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#FF00FF', '#00FFFF',&lt;br&gt;
    '#000000', '#FFFFFF', '#808080', 'transparent'&lt;br&gt;
];&lt;/p&gt;

&lt;p&gt;// Define the base URL&lt;br&gt;
const baseUrl = '&lt;a href="https://localhost/mysite"&gt;https://localhost/mysite&lt;/a&gt;'; // Change this to your actual WordPress site URL&lt;/p&gt;

&lt;p&gt;// Define your API key&lt;br&gt;
const apiKey = '4w5vhI8thAHiV4iuZqxWQ3Zz';&lt;/p&gt;

&lt;p&gt;// Define the PixelArtApp component&lt;br&gt;
const PixelArtApp = () =&amp;gt; {&lt;br&gt;
    // Define state variables&lt;br&gt;
    const [selectedColor, setSelectedColor] = useState(colors[0]);&lt;br&gt;
    const [pixels, setPixels] = useState(Array(256).fill('transparent'));&lt;br&gt;
    const [hasChanged, setHasChanged] = useState(false);&lt;br&gt;
    const [isDrawing, setIsDrawing] = useState(false); // Track drawing state&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Load saved pixel data from the server on component mount
useEffect(() =&amp;gt; {
    fetch(`${baseUrl}/wp-json/pap/v1/pixels`, {
        headers: {
            'Authorization': `Bearer ${apiKey}` // Include your API key in the Authorization header
        }
    })
        .then(response =&amp;gt; response.json())
        .then(data =&amp;gt; {console.log({...data}); /*setPixels(data)*/})
        .catch(error =&amp;gt; console.error('Error loading pixel data:', error));
}, []);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;};&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
