How to use n8n variables in HTTP Request

Describe the problem/error/question

I need to add a variable to my HTTP request and my request looks like this

http://o.net:1804/Testing/oslc/am/qc/?oslc.where=dcterms:type=“Package” and dcterms:modified=“2023-12-18”& useridentifier=$(useridentifier)

Method: GET

and the API is not approving the credentials which is the value after useridentifier=.

The useridentifier (token) has the value

D6237DD4-7975-44a8-9511-E5D775479C86}

Which is correct.

What is the error message (if any)?

NA

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

useridentifier

D6237DD4-7975-44a8-9511-E5D775479C86}

Information on your n8n setup

**n8n version:1.20.0, Community edition

**Database (default: SQLite): (I have no idea)

**n8n EXECUTIONS_PROCESS setting (default: own, main):Default

**Running n8n via (Docker, npm, n8n cloud, desktop app):Docker

**Operating system:Windows 10

You can reference the data via:

{{ $json.useridentifier }}

Here the adjusted workflow:

1 Like

Still some issue. When I look at the network it includes the variable, not the value of the variable.
{headers: {…}, method: ‘GET’, uri: 'http://OBFUSCATED useridentifier={{ $json.useridentifier }}

@TommyK , perhaps you meant to strip your identifier of the curly brackets. The original value (as I remember from another post Extract data from http response) is in the form {<SOME_ID>}.

If that is the case, you can update the extraction of useridentifier in “Edit Fields” node like this, {{ $json["rdf:RDF"]["ss:login"]["ss:useridentifier"].slice(1,-1) }}.

Another point to note is you are using spaces where they are not expected. The query string has to be in the form ?key1=value1&key2=value2. However, I can see a space which would become part of the “key” as in & useridentifier={{ $json.useridentifier }} (note a space after &). That is the key will become %20useridentifier instead of just useridentifier.

Generally speaking I find your querystring odd-looking. Are you sure it is in correct format? For visibility, it is like this, http://o.net:1804/Testing/oslc/am/qc/?oslc.where=dcterms:type="Package" and dcterms:modified="2023-12-18"& useridentifier={{ $json.useridentifier }}. In particular, note this, oslc.where=dcterms:type="Package" and dcterms:modified="2023-12-18". This actually will be transformed after URL encoding into oslc.where=dcterms%3Atype%3D%22Package%22%20and%20dcterms%3Amodified%3D%222023-12-18%22. That is, the key will be just oslc.where and the value will be dcterms%3Atype%3D%22Package%22%20and%20dcterms%3Amodified%3D%222023-12-18%22. Is it really the correct and expected key/value pair?

I agree it is a bit odd. But it is intended to work like that.

https://sparxsystems.com/enterprise_architect_user_guide/14.0/model_repository/oslc_where.html

Examples

Retrieves all Resources with the name of ‘Class1’.|
|2|http://localhost:480/firebird_model/oslc/am/qc/?oslc.where=dcterms:title=“Class1” and dcterms:type=“Class”

Retrieves all Enterprise Architect ‘Class’ type Resources with the name of ‘Class1’.|
|3|http://localhost:480/firebird_model/oslc/am/qc/?oslc.where=dcterms:type=“Activity” and dcterms:created > “2019-05-01”

or

http://localhost:480/firebird_model/oslc/am/qc/?oslc.where=ss:resourcetype =“Element” and dcterms:type=“Activity” and dcterms:created > “2019-05-01”

Retrieves all Enterprise Architect Activity type Resources that were created after 2019-05-01.|

So maybe it is best if I try to explain what I want.

When using Sparx EA OSLC you access it with a Rest Call.The first call is to get a token, unless you already have one.

that is what is read out using a POST method where you have a body with your userid and password.

The response from the first call is:

<?xml version="1.0" encoding="UTF-8"?>

<rdf:RDF xmlns:rdf=“http://www.w3.org/1999/02/22-rdf-syntax-ns#” xmlns:ss=“http://www.sparxsystems.com.au/oslc_am#” xmlns:foaf=“FOAF Vocabulary Specification”>ss:loginss:version5.1.128.2650</ss:version>ss:readonlyconnectionfalse</ss:readonlyconnection>ss:securityenabledmodeltrue</ss:securityenabledmodel>ss:modelrepositoryMicrosoft SQL Server</ss:modelrepository>ss:prolicenseTeam Server</ss:prolicense>ss:prolicenseexpiry2024-06-22</ss:prolicenseexpiry>ss:userfullnamefoaf:Personfoaf:nameAPI User</foaf:name>foaf:nickapiUser1</foaf:nick></foaf:Person></ss:userfullname>ss:useridentifier{6E08DBAD-C1CD-4bc8-A309-60C2988E2A5D}</ss:useridentifier>ss:defaultdiagramidentifierdg_{B48E9898-DE9B-4f4e-91F5-2DE3FF8EA595}</ss:defaultdiagramidentifier>ss:elementpermissiontrue</ss:elementpermission>ss:lockelementpermissiontrue</ss:lockelementpermission>ss:diagramcreatepermissiontrue</ss:diagramcreatepermission>ss:diagramupdatepermissiontrue</ss:diagramupdatepermission>ss:testpermissiontrue</ss:testpermission>ss:resourceallocationpermissiontrue</ss:resourceallocationpermission>ss:maintenanceitempermissiontrue</ss:maintenanceitempermission>ss:projectmanagementitempermissiontrue</ss:projectmanagementitempermission>ss:relationshipmatrixpermissiontrue</ss:relationshipmatrixpermission></ss:login></rdf:RDF>

I need to extract the value for ss:useridentifier to be used in the second call.

With the readout token I can make a second call.
This as a GET method.
In my querystring I must include my token as useridentifier=TOKEN_FROM_FIRST_CALL

http://o.net:1804/Testing/oslc/am/qc/?oslc.where=dcterms:type=“Package” and dcterms:modified=“2023-12-18”& useridentifier={968CD2EB-1234-4f4f-BFBA-FD0F6D9BCA4B}

Thanks. Makes sense. In that case the only obvious problem would be a space after &. That is the Jan’s example of the URL would be http://o.net:1804/Testing/oslc/am/qc/?oslc.where=dcterms:type="Package" and dcterms:modified="2023-12-18"&useridentifier={{ $json.useridentifier }} (space removed).

1 Like