# Applying the API instructions in KNIME

**URL:** <https://forum.knime.com/t/applying-the-api-instructions-in-knime/47045>\
**Category:** KNIME Analytics Platform\
**Created:** [September 13, 2022, 2:28pm UTC](https://forum.knime.com/t/applying-the-api-instructions-in-knime/47045 "2022-09-13T14:28:46Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![badger101](https://forum-cdn.knime.com/user_avatar/forum.knime.com/badger101/32/45755_2.png) [@badger101](https://forum.knime.com/u/badger101)\
**Post date:** [September 13, 2022, 2:28pm UTC](https://forum.knime.com/t/applying-the-api-instructions-in-knime/47045/1 "2022-09-13T14:28:46Z")

</div>

Greetings!

I would like to use the Facebook Library Ad API. As I’m reading the API documentation, I think I’m gonna need some help to do it if I am to use KNIME.

The documentation link I’m referring to is here:

> **[Ad Campaign Structure - Marketing API - Dokumentation - Facebook for Developers](https://developers.facebook.com/docs/marketing-api/campaign-structure)**
>
> Use the campaign structure to optimize and manage your ads. You can control what you spend on each audience, determine when the audience will see your ads, and see metrics for each audience.

The curl command as shown in the link is:

```auto
curl -G \
  -d 'end_time=1517287567' \
  -d 'fields=impressions,inline_link_clicks,spend' \
  -d 'access_token=<ACCESS_TOKEN>' \
  https://graph.facebook.com/v2.11/<CAMPAIGN_ID>/insights

```

There is also the Java Business SDK command provided in the documentation as alternative:

```auto
APINodeList<AdsInsights> adsInsightss = new Campaign(<CAMPAIGN_ID>, context).getInsights()
 .setParam("end_time", end_time)
 .requestField("impressions")
 .requestField("inline_link_clicks")
 .requestField("spend")
 .execute();

```

Background info:

- I’m not a coder.
- I have obtained my access tokens.
- I’m only familiar with the HTTP Retriever node that I used in past projects, but that node is simple and I didn’t need any authorization for those other projects.

Based on these instructions, how do I apply them in KNIME? Perhaps the GetRequest Node or the Java Snippet Node can be of use?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![qqilihq](https://forum-cdn.knime.com/user_avatar/forum.knime.com/qqilihq/32/50_2.png) [@qqilihq](https://forum.knime.com/u/qqilihq)\
**Post date:** [September 13, 2022, 3:12pm UTC](https://forum.knime.com/t/applying-the-api-instructions-in-knime/47045/2 "2022-09-13T15:12:43Z")

</div>

Hi badger101,

that request is in fact rather simple. The CURL translates to a request URL as follows using GET:

```nohighlight
https://graph.facebook.com/v2.11/<CAMPAIGN_ID>/insights?end_time=1517287567&fields=impressions,inline_link_clicks,spend&access_token=<ACCESS_TOKEN>'

```

`-G` means “GET”, `-d` are (in case of GET) the query params.

This you can simply pass as one string column into the [HTTP Retriever](https://nodepit.com/node/ws.palladian.nodes.retrieval.HttpRetrieverNodeFactory2).

If you want to acquire the access token through your workflow (instead of passing it statically), you can also have a look at this one:

> **[OAuth Connector \[BETA\] — NodePit](https://nodepit.com/node/ws.palladian.nodes.oauth.OAuthNodeFactory)**
>
> Authenticate at 50+ OAuth APIs.

–Philipp

---

<div class="post-metadata">

**Author:** ![badger101](https://forum-cdn.knime.com/user_avatar/forum.knime.com/badger101/32/45755_2.png) [@badger101](https://forum.knime.com/u/badger101)\
**Post date:** [September 13, 2022, 3:34pm UTC](https://forum.knime.com/t/applying-the-api-instructions-in-knime/47045/3 "2022-09-13T15:34:47Z")

</div>

Thank you @qqilihq , I’ll try it out later today, but this looks promising at first glance. Will update here!

---

<div class="post-metadata">

**Author:** ![badger101](https://forum-cdn.knime.com/user_avatar/forum.knime.com/badger101/32/45755_2.png) [@badger101](https://forum.knime.com/u/badger101)\
**Post date:** [September 14, 2022, 11:05am UTC](https://forum.knime.com/t/applying-the-api-instructions-in-knime/47045/4 "2022-09-14T11:05:26Z")

</div>

I have marked this as solved, since the query parameters explained above are what I was looking for.

@qqilihq Thank you again. As a side question, do you know if there’s a way I can read .har files with Knime? (if this requires a lengthy answer, I can make a separate forum post)

---

<div class="post-metadata">

**Author:** ![Daniel\_Weikert](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/d/e47c2d/32.png) [@Daniel\_Weikert](https://forum.knime.com/u/Daniel_Weikert)\
**Post date:** [September 14, 2022, 4:41pm UTC](https://forum.knime.com/t/applying-the-api-instructions-in-knime/47045/5 "2022-09-14T16:41:12Z")

</div>

Should be possible with python package

> **[haralyzer](https://pypi.org/project/haralyzer/)**
>
> A python framework for getting useful stuff out of HAR files

br

---

<div class="post-metadata">

**Author:** ![qqilihq](https://forum-cdn.knime.com/user_avatar/forum.knime.com/qqilihq/32/50_2.png) [@qqilihq](https://forum.knime.com/u/qqilihq)\
**Post date:** [September 15, 2022, 11:37am UTC](https://forum.knime.com/t/applying-the-api-instructions-in-knime/47045/6 "2022-09-15T11:37:05Z")

</div>

… beside that:

Generally a HAR is “just” a JSON, so you can also parse it manually through the [JSON-related](https://nodepit.com/category/struct-data/json) nodes.

---

<div class="post-metadata">

**Author:** ![badger101](https://forum-cdn.knime.com/user_avatar/forum.knime.com/badger101/32/45755_2.png) [@badger101](https://forum.knime.com/u/badger101)\
**Post date:** [September 15, 2022, 12:21pm UTC](https://forum.knime.com/t/applying-the-api-instructions-in-knime/47045/7 "2022-09-15T12:21:20Z")

</div>

Yes I figured that out yesterday after doing some Googling. Was able to do it via Json Reader 😁 (Turns out the File Reader Complex can do it too).

---

<div class="post-metadata">

**Author:** ![badger101](https://forum-cdn.knime.com/user_avatar/forum.knime.com/badger101/32/45755_2.png) [@badger101](https://forum.knime.com/u/badger101)\
**Post date:** [September 18, 2022, 8:31am UTC](https://forum.knime.com/t/applying-the-api-instructions-in-knime/47045/8 "2022-09-18T08:31:11Z")

</div>

@qqilihq Hi Philipp, regarding the OAuth Connector Beta Node, I tried using it for my Twitter API. I know this thread is for Facebook, but since you recommended the node here, I’d like to point out that I found the node to not work with Twitter, as you’ve been made known in this forum thread → [here](https://forum.knime.com/t/twitter-oauth2-0-node/43108) which was closed.

Here’s what happened:

- I keyed in my API & Secret Keys, and proceeded with the Authorize button. But nothing occurred. (No browser window pops out)

- Since I thought this might have something to do with my default Knime configuration just to check it out, I went to the File Menu \> Preferences \> General \> Web Browser, and my default setting was like this:

 ![browsersetup](https://forum-cdn.knime.com/uploads/default/original/3X/8/3/837ad39b28b312b9a4c57bbe8e5b4759bf77eca6.png)

- I retried the Twitter API access, but the issue wasn’t resolved - no browser window pops out.

- I changed my preferences to this:

 ![browsersetp2](https://forum-cdn.knime.com/uploads/default/original/3X/7/5/75e8615248f804416187548d910c49a298ad1e53.png)

And still got no results. Just to play around, I randomly choose some of the other services apart from Twitter, but this time with dummy access tokens, and I managed to get the Chrome browser to pop out. I’d appreciate it if you can take a second look at the Twitter issue 😁 I just got my v2 access token this week, so in the meantime I’ll have a go at the Twitter API Connector Node.

---

<div class="post-metadata">

**Author:** ![qqilihq](https://forum-cdn.knime.com/user_avatar/forum.knime.com/qqilihq/32/50_2.png) [@qqilihq](https://forum.knime.com/u/qqilihq)\
**Post date:** [September 18, 2022, 10:39am UTC](https://forum.knime.com/t/applying-the-api-instructions-in-knime/47045/9 "2022-09-18T10:39:11Z")

</div>

Hi Badger,

thanks for the feedback!

> - I keyed in my API & Secret Keys, and proceeded with the Authorize button. But nothing occurred. (No browser window pops out)

1. Currently some errors are logged to the console\*, but might be filtered out if your log level is too high. You can enable `DEBUG` logging and probably see some helpful output in the console.

2. If you’d see the `DEBUG` log, I’d highly suspect that you’ll see something like this along the lines:

3. If that’s the case, you’ll need to set up “User authentication set up” in your Twitter project:

I’m still collecting plenty of feedback for this node, so please do let me know if that helps!

Best,  
Philipp

\*) We’ll improve this in the next release to show a proper error dialog as console output usually just gets lost

---

<div class="post-metadata">

**Author:** ![badger101](https://forum-cdn.knime.com/user_avatar/forum.knime.com/badger101/32/45755_2.png) [@badger101](https://forum.knime.com/u/badger101)\
**Post date:** [September 18, 2022, 3:39pm UTC](https://forum.knime.com/t/applying-the-api-instructions-in-knime/47045/10 "2022-09-18T15:39:17Z")

</div>

@qqilihq , This is the error I’m seeing after clearing the log file and replicating the process:

2022-09-18 23:37:27,476 : WARN : main : : Node : OAuth Connector [BETA] : 3:1 : Please configure the node and authorize access through the corresponding button.  
2022-09-18 23:37:33,271 : WARN : main : : Node : OAuth Connector [BETA] : 3:1 : Please configure the node and authorize access through the corresponding button.

---

<div class="post-metadata">

**Author:** ![badger101](https://forum-cdn.knime.com/user_avatar/forum.knime.com/badger101/32/45755_2.png) [@badger101](https://forum.knime.com/u/badger101)\
**Post date:** [September 18, 2022, 4:01pm UTC](https://forum.knime.com/t/applying-the-api-instructions-in-knime/47045/11 "2022-09-18T16:01:25Z")

</div>

> [@qqilihq](#):
>
> `http://localhost:55931`

Update:

Okay, I have enabled the User authentication setup as instructed, and I managed to get access via the node now. 😁 I’m wondering why does Twitter give me these two additional tokens: **Client ID & Client Secret ID** right after I set up the authentication, when the only tokens I need are the API key and the API secret key (for the OAuth Beta Node) (and Access token & Access Token Secret for the Twitter API Connector).

Anyway, here’s the screen showed to me once authenticated:

 ![accessgranted](https://forum-cdn.knime.com/uploads/default/original/3X/1/1/1161fa5dd532139b5d9362033923303646fdd5eb.png)

And I want to ask about this ‘refresh token’ section which appears ‘missing’ in the output port of the OAuth.

 ![nodeoutput](https://forum-cdn.knime.com/uploads/default/original/3X/d/7/d7a84a8f9de49b8227ebbac1075f042c732fc057.png)

I’m not sure under what circumstances will I need a ‘refresh token’, and if I do, how do I set it up in the OAuth node? The doc gives me this info:

 ![refreshtoken](https://forum-cdn.knime.com/uploads/default/original/3X/1/e/1e21668085f8320e7a613b03ec85e827c3aa284b.png)

My project doesn’t require me to make POST requests, rather only GET requests. I’m hoping/assuming this “offline.access” scope, _whatever that means_, will not be troubling me in any way. 🤣

---

<div class="post-metadata">

**Author:** ![badger101](https://forum-cdn.knime.com/user_avatar/forum.knime.com/badger101/32/45755_2.png) [@badger101](https://forum.knime.com/u/badger101)\
**Post date:** [September 20, 2022, 4:08pm UTC](https://forum.knime.com/t/applying-the-api-instructions-in-knime/47045/12 "2022-09-20T16:08:48Z")

</div>

I haven’t had the chance until today to make my query.

So far, I always get 404 errors. Then I have a look around the Twitter docs, it seems that I will have to convert this curl command :

 ![whatif](https://forum-cdn.knime.com/uploads/default/original/3X/1/f/1fa18f6067f507a549ff8d49e65fdd215b57be15.png)

I have the ID and the bearer token, but I don’t know how to convert this to the complete URL. The difference between this curl and that of the Facebook’s:

- It contains spaces

- It uses -H instead of -d

Kindly help me out @qqilihq when you get back.

---

<div class="post-metadata">

**Author:** ![qqilihq](https://forum-cdn.knime.com/user_avatar/forum.knime.com/qqilihq/32/50_2.png) [@qqilihq](https://forum.knime.com/u/qqilihq)\
**Post date:** [September 21, 2022, 4:12pm UTC](https://forum.knime.com/t/applying-the-api-instructions-in-knime/47045/13 "2022-09-21T16:12:41Z")

</div>

`-H` means header, i.e. you send the following information in the header.

1. Add a column called `Authorization` to your table
2. Put the value `Bearer XXXXXXXXXXXXXXXX` as value
3. Select it in the HTTP Retriever’s “Headers” tab.

That should do 🙂

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [September 28, 2022, 4:13pm UTC](https://forum.knime.com/t/applying-the-api-instructions-in-knime/47045/14 "2022-09-28T16:13:32Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
