Error: Invalid Key on POST

edited September 2021 in API Vote Up0Vote Down
Any POST request I try to do either in my code or postman I get Status: 403 Error: "Invalid Key" I am using that same key in GET requests to pull back order data though.

Here's how I'm structuring the request:

https://api.brickowl.com/v1/order/set_status?key=<key>&order_id=<order number>&status_id=3

I'm not sure what I'm doing wrong.

Comments

  • 15 Comments sorted by Votes Date Added
  • POST requests would need any parameters to be sent in the body rather than in the request url
  • I've also tried that. And just tried it again now. I'm still getting Invalid Key no matter how I try to format the body. I'm sending key, order_id, and status_id.

    Can you update the top part of the API docs with the expected payload? Right now it says all requests should look like my first example with query parameters.
  • Here's my node code in case that's helpful

    request({
    method: "POST",
    uri: "https://api.brickowl.com/v1/order/set_status",
    body: {
    key: process.env.brickowl,
    order_id: orderid,
    status_id: 3
    },
    json: true
    })
  • It looks like that’s being formatted as json. It would need to be sent as a standard post request. The format will depend on the language used
  • OK so it needs to be sent as form-data which I was able to successfully send the request via postman. Can you update the API docs to make that clear?
  • Just got it working in code as well. Thanks for the help.
  • Hi Ralph, i have the same Problem. Is it possible to share your solution as code here?
  • Hi, I try to send a POST with a order-status change with javascript and node.js. The problem is near to ralphs_bricks-problem. I wrote a code with fetch-method. But it doesn`t work. The response is "invalid key". The key itself is correct because I`m successfully able to send GET-API-requests. Has anybody an idea where the problem is? Here is the code:
  • const fetch = require('node-fetch');

    // Send the POST request
    fetch('https://api.brickowl.com/v1/order/set_status', {
    method: 'POST',
    headers: {
    'Content-Type': 'application/json',
    'Authorization': "APIKEY" //has to be replaced
    },
    body: JSON.stringify({
    order_id: 9229622,
    status_id: 4
    })

    })
    .then(res => {
    return res.json()
    })
    .then(data => console.log('data:', data))
    .catch(error => console.error('Error:', error))
  • After a while, I tried another method called axios. But the response is again "invalid key". Here is the code:
  • const axios = require('axios');
    // Replace with your actual BrickOwl API endpoint
    const brickOwlApiUrl = 'https://api.brickowl.com/v1/order/set_status';

    // Replace with the data you want to send in the request body
    const postData = {
    order_id: '9229622', // Replace with the order ID you want to update
    new_status: '3' // Replace with the desired status
    // Add any other data you need to send
    };

    // Set your authentication headers, e.g., using a Bearer token
    const headers = {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer APIKEY', //has to be changed
    };

    // Make the POST request
    axios.post(brickOwlApiUrl, postData, { headers })
    .then((response) => {
    console.log('Response:', response.data);
    // Handle the response data here
    })
    .catch((error) => {
    console.error('Error:', error);
    // Handle the error here
    });
  • Has anybody a solution or a javascript code template?
  • The key doesn’t go in the headers. It needs to go in the body of the request. The request should not be JSON
  • Ok. Now I have the right code. Thanks..
  • const request = require('request');

    const url = 'https://api.brickowl.com/v1/order/set_status';
    const body = {
    key: 'APIKEY',
    order_id: 4109948,
    status_id: 2
    };

    request.post({
    url: url,
    form: body,
    }, (error, response, body) => {
    if (error) {
    console.error('There was an error:', error);
    } else if (response.statusCode !== 200) {
    console.error('Status code:', response.statusCode);
    } else {
    console.log('Data received:', body);
    }
    });
Sign In or Register to comment.