Click here to Skip to main content
15,868,055 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am tried to create an application that calls an GraphQL API to create a record. The application has basic-authentication and base uri (graphql). I am able to create customer using PostMan but not from VB.net application.

mutation CreateCustomer($input: CreateCustomerInput!) {
  createcustomer(input: $input) {
    customer {
      id
      firstname
	  lastname
	  email
      address {
        streetAddress
        city
        state
        zipcode
		country
      }
      contacts {
          home
          mobile
      }
	  optout
    }
  }
}

--Variables

{
  "input": {
    "customer": {
      "firstname": "John",
      "lastname": "Smith",
      "email": "jsmith@myemail.com",
      "address": {
        "streetAddress": "123 Any St",
        "city": "Big City",
        "state": "New State",
        "zipcode": "123456",
        "country": "USA"
      },
      "contacts": {
              "home": 8888901234,
              "mobile" : 9991237890
            }
      ,
      "optout": false
    }
  }
}


Converted Code:

Dim client = New RestClient("https://payments.XXXXXXX-api.com/graphql")
        'client.Timeout = -1
        Dim request = New RestRequest(Method.Post)
        request.AddHeader("XXXXXXX-Version", "2020-06-16")
        'request.AddHeader("Authorization", "Basic aG5mYmJwOWo0MnkY4YjRjODhmODFmNg==")
        
        request.AddHeader("Content-Type", "application/json")
        request.AddParameter("application/json", "{""query"":""mutation CreateInStoreLocation($input: CreateCustomer!) {\n  createcustomer(input: $input) {\n    customer {\n      id\n      firstname\n      lastname\n      address {\n        streetAddress\n        city\n        state\n        zipcode\n        country\n      }\n      contacts {\n          home\n          mobile\n      }\n    }\n  }\n}"",""variables"":{""input"":{""customer"":{""firstnamename"":""John"",""internalName"":""Smith"",""address"":{""streetAddress"":""123 Any St"",""city"":""Big City"",""state"":""New State"",""zip code"":""123456"",""country"":""USA""},""contacts"":{""home"":8888901234,""mobile"":9991237890},""optout"":false}}}}", ParameterType.RequestBody)
        
		'Dim response As iRestResponse = client.Execute(request)
        
		Dim response As RestResponse = client.Execute(request)
        Console.WriteLine(response.Content) 


What I have tried:

I have tried using the Postman C# code to run in VB.Net application. It executes but no updates and no errors.
Posted
Updated 14-Jan-23 9:12am
v3

1 solution

Quote:
It executes but no updates and no errors.

Without your converted code, there is nothing we can do to help you - we don't have any access to it or your data, and without that we are just whistling in the dark.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
v2
Comments
Member 15809593 14-Jan-23 15:56pm    
Thanks for your response. I am very new to the API and GraphQL. I have been using Visual Basic for years. But I never coded for APIs. I have updated the question and added the converted code. I have also already tried debugging. The response.content is showing up as blank. There is no error or any other response code. Do I need to import the GraphQL clients or anything else to make it work. Any suggestions?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900