# Call API inside the action in Bubble Plugin

There are times when you need to call the API within the action section instead of the API section, but how do you do it?

Let me demonstrate with an example.

I will call this GET API: https://api.thecatapi.com/v1/images/search

**GET API Example -**  
Copy and paste this code into the action function.

```javascript

    const response = await fetch('https://api.thecatapi.com/v1/images/search')
    const body = await response.json()
    const cat_image = body[0].url
    
    return {
        "cat_image":cat_image 
    }
```

**POST API Example-**

```javascript
 const url = 'https://dummy.restapiexample.com/api/v1/create';
//body request
  const data = {
    name: 'value1',
    salary: 'value2',
    age: 'value2'
  };	


  try {
    const response = await fetch(url, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(data)
    });

    const responseData = await response.json();
    console.log('Success:', responseData);
  } catch (error) {
    console.error('Error:', error);
  }
```

---

That's all for this blog. Subscribe for more future updates. Thank you!

Follow me on [Twitter](https://twitter.com/NocodeTalks).

**Checkout My Bubble Plugin Course** - Use coupon code "THEBUBBLEGROUP" at checkout for 10% discount.

%[https://nocodetalks.co/bubbleplugin]
