# Web api chatgpt

**URL:** https://community.thunkable.com/t/web-api-chatgpt/3619142
**Category:** Web API's
**Created:** [March 2, 2025, 4:40am UTC](https://community.thunkable.com/t/web-api-chatgpt/3619142 "2025-03-02T04:40:07Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Van\_antics](https://avatars.discourse-cdn.com/v4/letter/v/3d9bf3/32.png) [@Van\_antics](https://community.thunkable.com/u/Van_antics)
#### Post date: [March 2, 2025, 4:40am UTC](https://community.thunkable.com/t/web-api-chatgpt/3619142/1 "2025-03-02T04:40:07Z")

</div>

in none drag and drop could someone guide me how to get chatgps API to work in web API if that’s possible

````auto
> import OpenAI from "openai";
> const openai = new OpenAI();
> const completion = await openai.chat.completions.create({
> model: "gpt-4o",
> store: true,
> messages: [
> {"role": "user", "content": "write a haiku about ai"}
> ]
> });
> ```

what line of codes to what blocks. eeehhhh
thanks
````

---

<div class="post-metadata">

### Author: ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)
#### Post date: [March 2, 2025, 5:20am UTC](https://community.thunkable.com/t/web-api-chatgpt/3619142/2 "2025-03-02T05:20:10Z")

</div>

This post and the topic it’s in might help you get started:

> [@Open Ai source ChatGPT API undefined response](https://community.thunkable.com/t/open-ai-source-chatgpt-api-undefined-response/2972058/4):
>
> Your API Request is Incorrect Try These:

---

<div class="post-metadata">

### Author: ![Van\_antics](https://avatars.discourse-cdn.com/v4/letter/v/3d9bf3/32.png) [@Van\_antics](https://community.thunkable.com/u/Van_antics)
#### Post date: [March 2, 2025, 6:07pm UTC](https://community.thunkable.com/t/web-api-chatgpt/3619142/3 "2025-03-02T18:07:13Z")

</div>

i got it to work but had to do something like this as I could not get the objects to work lol

 ![Screenshot 2025-03-03 at 7.02.16 AM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/3/43f23f9ba4ea53f20e8bb3c720144bd2a44310f7.png)  
lol but it works

any idea how to do it with object blocks.

 ![Screenshot 2025-03-03 at 7.06.38 AM](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/2/52f982119347c303838c364bd9a4ddaa5461bb0b.png)  
opens to null

---

<div class="post-metadata">

### Author: ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)
#### Post date: [March 2, 2025, 7:02pm UTC](https://community.thunkable.com/t/web-api-chatgpt/3619142/4 "2025-03-02T19:02:54Z")

</div>

> [@Van\_antics](#):
>
> any idea how to do it with object blocks.

What is the full response from the green block **as text** and which properties are you trying to get from it? If you can copy the response – I usually assign it to a Text Input so I can copy it – and paste it into [Best JSON Viewer and JSON Beautifier Online](http://codebeautify.org/jsonviewer) as valid JSON, then you can see the path to specific properties.

I explain that here: [API JSON Tutorial (Video)](https://community.thunkable.com/t/api-json-tutorial-video/1140575)

---

<div class="post-metadata">

### Author: ![Van\_antics](https://avatars.discourse-cdn.com/v4/letter/v/3d9bf3/32.png) [@Van\_antics](https://community.thunkable.com/u/Van_antics)
#### Post date: [March 2, 2025, 8:11pm UTC](https://community.thunkable.com/t/web-api-chatgpt/3619142/5 "2025-03-02T20:11:47Z")

</div>

thanks for replying  
this is what i have “response X” is where the reply is

```auto
{
  "id": "chatcmpl-B6juxBD3GsZdCT8oVkQynTeaifMk8",
  "object": "chat.completion",
  "created": 1740946128,
  "model": "gpt-4o-2024-08-06",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "response X.",
        "refusal": null
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 139,
    "completion_tokens": 25,
    "total_tokens": 164,
    "prompt_tokens_details": {
      "cached_tokens": 0,
      "audio_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    }
  },
  "service_tier": "default",
  "system_fingerprint": "fp_eb9dce56a8"
}

```

---

<div class="post-metadata">

### Author: ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)
#### Post date: [March 3, 2025, 3:10am UTC](https://community.thunkable.com/t/web-api-chatgpt/3619142/6 "2025-03-03T03:10:38Z")

</div>

The JSON text has to be formatted using the \</\> button in the forums toolbar so I went ahead and changed that for you. When I paste the response into the code beautify site and click on the “content” property that has the “response X.” value, the path is shown at the top:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/1/b15ff98279f72fb73576e429b0827ff40cf2c567.png)

Because Thunkable lists begin at 1, not 0, the property you need to get in Thunkable is:

**choices[1].message.content**

You can use that in the `get property of object` block but you’ll need to use the `get object from JSON` block with the green `response` block to convert the JSON response to an object.
