-1

I am trying to connect to a website and they have given me :

Url: https://api.demo...
headers:"x-api-key" and "x-api-user"

I do not know how to make the connection with them,I tried the code below:

const query = ` 
query {
   some query here
    }
`;
const url = ``

const opts = {
  method: "POST",
  headers: { "x-api-key": ,
    "x-api-user": , },
  body: JSON.stringify({ query })
};

Is this the right way? when I run it npm start=> App Crashes I am new to javascript and I dont even know how to make the search in google,can someone please guide me to a tutorial,link or please respond with the right way?

Thank you for your understanding

0

1 Answer 1

0

You can do it using the fetch call.

const query = `query {
  Some query
}`;
 
fetch(url, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
  },
  body: JSON.stringify({
    query
  })
})
  .then(r => r.json())
  .then(data => console.log('data returned:', data));
Sign up to request clarification or add additional context in comments.

3 Comments

That's going to throw a reference error because fetch isn't defined.
@Quentin did you close my question?Please this is not the same...where do i put my credentials?
@Quentin can you please let me know,I have had not a response

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.